3447 Posts in 1032 Topics by 872 members
|Go to End|
14 July 2011 at 8:30am Last edited: 15 July 2011 5:56am
Hi, I've run into a problem on my site: http://ninnle.com/server-browser/
I've set up a simple bit of AJAX functionality, which requests some gameserver info etc, returns it as ArrayData to an Ajax template.
However, I want to select an Image DataObject depending on the "map" value from the array of server details...
I want to do this so I can perform cropping and such on said image.
Basically I want to send the ArrayData and a DataObject to the template, or merge the two and send. Anybody got any ideas?
At the moment I'm just putting in the raw image from the filesystem.
15 July 2011 at 7:06am
I'm not sure if I fully understand what you're trying to do. But if you're trying perform image transformations based on a URL Parameter you could always extend the Image object and add the functions that pull the URL Param. I usually extend my Image object just to customize default image quality parameter and to embed extra data properties in image tag for jQuery stuff
15 July 2011 at 7:54am
Ah sorry, I haven't explained myself properly.
That page has a list of game servers the user can query. Upon clicking that, it sends a request to /ServerDetails/$ID of server in the DB, it then gets the stored IP for this server from the ID. IT then sends a request for a server info, it returns a packet, i decode this, split into an array, wrap in ArrayData and put it in ServerAjax.ss, which is then served to the user. I want to use the "map" array value and get the image dataobject on the server corresponding to this map value (the map that is currently playing on the game server) so I can then manipulate it in the ServerAjax.ss.
Can I resize in the controller and just add a filename to the ArrayData? Would this mean the requested map image would be manipulated every time the person requested it, or will silverstripe realise there's already a cached image there?
15 July 2011 at 8:14am
SilverStripe will cache all resized images in a _resized subfolder placed in the folder that contains the image. If an image exists in the Cache it will serve that one instead of generating a new one. If all you need is the name of the resized image you can do something like this in the template
<% control Image.SetWidth(250) %>
<% end_control %>
$Filename returns the relative path of image ie "assets/Uploads/.../filename.jpg"
you can also do this in the PHP by performing the manipulation on your image object and returning $image->Filename (you may need to call cacheFilename, I've never needed to call do it that way http://api.silverstripe.org/2.4/sapphire/filesystem/Image.html
|Go to Top|