I would need my publishers to be able to crop images dynamically from the admin panel, using (for example) jcrop; but the step would not be necessary. In the template, I would be able to call $Image.customCrop('thumbnail'), and the templating engine would fetch the 'thumbnail' data ($imageSizes['thumbnail']['width'] = 100, $imageSizes['thumbnail']['height'] = 70), and then check if a file exists. If the file does not, then it would revert to Silverstripe's native on-the-fly image generation and caching.
My requirements:
- Store custom models (thumbnail=>100x70; largeImage=>1024x768...), through _config
- leverage all of jcrops restrictions per-model (allow custom crop for a "articleImage", but enforce a ratio for "videoThumbnail")
- pop-up a modal window on post, but allow user to cancel it if he/she does not want to set a custom crop
- store the generated image in _resampled, like any other cached SS image, following the naming pattern in use.
I would be willing to contribute a module for all that, but I need a little help.
First of all, let me tell you how I envision this:
1) extend the $Image class, and add a method called customCrop($size, $height=NULL) which would allow to pass either a string as a single argument, or two numbers (width & height) to fall back to native behaviour (for quick development, you might not want to set all your sizes in the $sizes array from day one)
2) use a separate class for storing/retrieving sizes models, so this can be used independently from the javascript cropping behaviour (one might not need jcrop at all, but still find it handy to store presets and use them instead of always remembering the size of the website's thumbnails).
3) use the templating engine for rendition of the modal box, to allow power users to overwrite the admin window, or extend it.
So the loop would be:
A) in the template a customCrop('thumbnail') is found -> check the $sizes array for a key called 'thumbnail'
-> key found: retrieve width and height and revert to native ss behaviour (= fetch the file '_resampled/customCropWidthHeightfilename')
-> file found: return file
-> file not found: revert to setSize($sizes['thumbnail']['width'],$sizes['thumbnail']['height']), return the file
-> key not found: revert to setSize($defaultWidth,$defaultHeight), return the file
B) in the cms, a new $extendedImage object is created
-> check for permissions to crop, if permissions are ok:
-> get options for the $extendedImage (forced ratio, forced size, ....)
-> fetch jcrop.ss, display the modal box
-> on submission, if there is data: generate the image, if no data, don't do anything
My questions:
1) Is there any SS project that goes in that direction, that I could fork/participate/simply use? I searched but didn't find any
2) How do I force a modal pop-up in the admin?
3) How can I use SS's native file storage function in order to write/retrieve a new _resampled image?
4) Can anyone provide pointers on how I should go from there? The loop A does not really pose any problem to me, but for the loop B (cms), I am completely lost
5) And finally, is anyone willing to contribute?