Not sure why Zencart doesn't do this - perhaps I'm missing something really basic in the configuration of the product - I admit I'm a newbie...
In any event once I turned my customer loose with his store he started uploading HUGE images.
He's not a computer geek and does not know how to resize images, he''s a business man but we use the Lightbox add-on and his images were taking over the screen, so I did a little digging around in the code last night and wrote this code this morning.
On his site I've established a maximum image size of 600 x 800 - you can change it to anything you want. I'm running on a dedicated centos 5.7 box and have Image Magick installed (which I use to resize the images). This code only works for JPG files but could easily be conditionalized to test the file extension and do gifs also. My customers only uses jpgs.
I don't profess to be a crackerjack programmer but I've written a decent amount of php over the years and it has always worked for me.
The code below is a snippet from /YOURADMINFOLDER/includes/classes/upload.php
look for this code:
PHP Code:if ($this->message_location == 'direct') {
$messageStack->add(sprintf(SUCCESS_FILE_SAVED_SUCCESSFULLY,$this->filename), 'success');
} else {
$messageStack->add_session(sprintf(SUCCESS_FILE_SAVED_SUCCESSFULLY,$this->filename), 'success');
}
return true;
and replace it with:
PHP Code:if ($this->message_location == 'direct') {
$messageStack->add(sprintf(SUCCESS_FILE_SAVED_SUCCESSFULLY,$this->filename), 'success');
} else {
$messageStack->add_session(sprintf(SUCCESS_FILE_SAVED_SUCCESSFULLY,$this->filename), 'success');
}
// mod jjj 2/23/12 to resize uploaded images
$theimage = $this->destination . $this->filename;
$myimg = ImageCreateFromJpeg($theimage);
$theimagew = imagesx($myimg);
$theimageh = imagesy($myimg);
$thestring = $theimage . " width=". $theimagew . " height=". $theimageh . "\n\r";
if ( ($theimagew > 600) or ($theimageh > 800) )
{
$newwidth = $theimagew;
$newheight = $theimageh;
while ( ($newwidth > 600) or ($newheight > 800) )
{
$newwidth = round ($newwidth * .99);
$newheight = round ($newheight * .99);
}
$syscmd = "mogrify -resize ". $newwidth . "x" . $newheight . " " . $theimage;
system($syscmd, $retval);
}
return true;


Reply With Quote
