Page 1 of 1
resizing images after upload
Posted: 17 Feb 2010, 13:58
by lancerus
The web provider I use has some strict process memory clamps, which means thumbnail creation crashes the web site unless I restrict uploaded images to something relatively small compared to today's cameras. What I did to solve this and keep my site friendly is still allow large images to get uploaded - but immediately resize them with an exec to convert after the upload. The code goes in controllers/ user.php and category.php. I can provide the code if interested.
Re: resizing images after upload
Posted: 17 Feb 2010, 20:23
by Jan
Hi, you can display the code here, but I think the exec is disabled on most servers
Jan
Re: resizing images after upload
Posted: 17 Feb 2010, 21:41
by lancerus
Here's an example. For hosts that dont support exec - resizing could be changed to do it in-line, then you'd have it covered for both the java path (client-side) or singleFileUpload path (server side). I have my resize size hard-coded at the moment as you can see. I cant do the in-line resize due to the memory size problem again. I tried that path first.
Code: Select all
if (!JFile::upload($file['tmp_name'], $filepath)) {
$errUploadMsg = JText::_("Unable to upload file");
$redirectUrl = $return;
return false;
} else {
// resize the uploaded image if required.
list($w,$h) = getimagesize($filepath);
if ($w > 1600 && $h > 1600) {
$cmd = "convert -resize 1600x \"$filepath\" \"$filepath\"";
exec($cmd, $output, $retval);
// if ($retval) we failed ...
if ($retval) {
$errUploadMsg = JText::_("Unable to resize file");
$redirectUrl = $return;
return false;
}
}
Re: resizing images after upload
Posted: 18 Feb 2010, 00:00
by Jan
Ok, thank you for this info.
Jan
Re: resizing images after upload
Posted: 10 Mar 2010, 23:58
by bepos
nice solution. But can you be a bit more specific where to put the code in the files?