Resizing images upload via a form

Permalink 1 user found helpful
I have tried suggestions regarding resizing images on the fly and have had no success.
Can anyone help me intercept a file/image uploaded by a user in a form, resize to a specific width (say 600px) and then save.

I know FRZ promised a revamp of the file system and mentioned resizing a while ago but I can't figure out where/how to do it.

I am using C5 5.4.0.5

 
RodneyC5 replied on at Permalink Reply
I have figured out a way to do this - hope this helps someone.

I created a file called SimpleImage.php based on the code designed by Simon Jarvis herehttp://www.white-hat-web-design.co.uk/articles/php-image-resizing.p...
I edited the names of the "load" and "save" functions in SimpleImage.php to be "loadim" and "saveim" just in case concrete had defined any public functions with those names.
I placed SimpleImage.php in the Root/elements folder.

Then I copied the core importer.php from /concrete/libraries/file to Root/libraries/file and then edited it as follows:
At about line 137 locate this code
$fv = File::add($filename, $prefix);

and insert this AFTER it to call the resize function
include(DIR_FILES_ELEMENTS . '/SimpleImage.php');
   $image = new SimpleImage();
   $image->loadim($fv->getPath());
   $image->resizeToWidth(600);
   $image->saveim($fv->getPath());


At about line 146 locate this code
$fv = $fr->getVersionToModify(true);

and add the same 5 lines of code AFTER it.
Thats it. This will resize any/all images to 600px width uploaded to the file manager or by form file upload.
(Other resizing options are available with the white-hat code mentioned above)
With a bit of extra code you could do this only if the user is not an administrator so that the site developer could still upload larger images when required.

Any suggestions for a simpler more code efficient way would be appreciated but this works for me.
jordanlev replied on at Permalink Reply
jordanlev
Hi Rodney,
Thanks for posting that. I had a similar idea recently: an option that is configurable in the dashboard that checks all uploaded files to see if they're larger than a certain width, height, or filesize, and if so it automatically resizes them down. I think this would be very helpful to alleviate the dreaded "I uploaded these 10 images from my camera and now the page takes forever to load" problem.

Unfortunately there's no way to do this prior to the upload, so it will still take a while for large images to make their way to the server (and the originals will still be living on the server so there might be space issues if you're being super cheap about web hosting).

But still a great option to have. If I ever have time to get around to it, I'll definitely be looking at your code here in more detail. Thanks again.

-Jordan

PS - I've seen some random mentions elsewhere on the internets about some new feature in Flash version 10 which allows for image resizing on the client prior to upload -- maybe when that's more developed it could be rolled into the C5 uploader (not expecting it will happen, though -- just a random thought).
RodneyC5 replied on at Permalink Reply
Thanks jordanlev,
Just a word of caution to all, this code works with single file uploads but does NOT with multiple uploads, not sure why yet but I am sure that could be solved.
Another great option would be to warn a user that the uploaded file is too large and could be blocked by the server settings in php.ini (or htaccess) - At the moment a user with camera starts sending pics via a form and if they are too big, the process just ends without a message.
jordanlev replied on at Permalink Reply
jordanlev
In case you're interested, I just saw this:
http://www.plupload.com/index.php...

(I don't think it would be easy to add this to concrete5, but just something to think about)
RodneyC5 replied on at Permalink Reply
Thanks I had a quick look and it is really interesting, will have a proper look and try it out. Thanks Jordanlev
staticfiction replied on at Permalink Reply
Hi RodneyC5,

Thanks so much for posting this. It works great! It actually optimises the images aswell as resizing (which is exactly what i was looking for). I tried the multiple upload as well and it worked fine (on 2 images)...so maybe the bug with the multi upload you experienced was caused by something else...unsupported or corrupt image/file format on one of the images maybe? just guessing....anyway, thanks again!
hursey013 replied on at Permalink Reply
hursey013
Was looking for a solution like this, using it on 5.4.2.2 - appears to be stable from my initial test - thank you very much.
tpwgd replied on at Permalink Reply
This method isn't working for me it just crashes my uploader can anyone suggest a solution?