Code:
/***************************************/
/* Changes To Limit Product Image Size */
/***************************************/
if(($this->file == 'products_image') && (strlen ($file['tmp_name']>0))) {
// Get The Image as a String
$pictureString = fread(fopen($file['tmp_name'], "rb"), $file['size']);
$image = imagecreatefromstring($pictureString);
// This validates whether or not a valid image was uploaded.
if ($image !== false) {
// Dimensions For The Uploaded Picture
$larWidth = 600;
$larHeight = 600;
$larLoc = DIR_FS_CATALOG_IMAGES . 'large/' . substr($file['name'], 0, -4).'_LRG' . substr($file['name'], -4);
$medWidth = 200;
$medHeight = 200;
$medLoc = DIR_FS_CATALOG_IMAGES . 'medium/' . substr($file['name'], 0, -4).'_MED' . substr($file['name'], -4);
$smallWidth = 100;
$smallHeight = 100;
$smallLoc = $file['tmp_name'];
// Set Current For All Sizes
$lWidth = $mWidth = $sWidth = $originalWidth = imagesx($image);
$lHeight = $mHeight = $sHeight = $originalHeight = imagesy($image);
// Large
if($lWidth > $larWidth) {
$lHeight = $lHeight / ($lWidth / $larWidth);
$lWidth = $larWidth;
}
if($lHeight > $larHeight) {
$lWidth = $lWidth / ($lHeight / $larHeight);
$lHeight = $larHeight;
}
if($lWidth != $originalWidth || $lHeight != $originalHeight) {
$newImage = imagecreatetruecolor($lWidth, $lHeight);
if(imagecopyresampled($newImage,$image,0,0,0,0,$lWidth,$lHeight,$originalWidth,$originalHeight)) {
@imagejpeg($newImage, $larLoc, 90);
}
}
else {
@imagejpeg($image, $larLoc, 90);
}
// Medium
if($mWidth > $medWidth) {
$mHeight = $mHeight / ($mWidth / $medWidth);
$mWidth = $medWidth;
}
if($mHeight > $medHeight) {
$mWidth = $mWidth / ($mHeight / $medHeight);
$mHeight = $medHeight;
}
if($mWidth != $originalWidth || $mHeight != $originalHeight) {
$newImage = imagecreatetruecolor($mWidth, $mHeight);
if(imagecopyresampled($newImage,$image,0,0,0,0,$mWidth,$mHeight,$originalWidth,$originalHeight)) {
@imagejpeg($newImage, $medLoc, 90);
}
}
else {
@imagejpeg($image, $medLoc, 90);
}
// Small
if($sWidth > $smallWidth) {
$sHeight = $sHeight / ($sWidth / $smallWidth);
$sWidth = $smallWidth;
}
if($sHeight > $smallHeight) {
$sWidth = $sWidth / ($sHeight / $smallHeight);
$sHeight = $smallHeight;
}
if($sWidth != $originalWidth || $sHeight != $originalHeight) {
$newImage = imagecreatetruecolor($sWidth, $sHeight);
if(imagecopyresampled($newImage,$image,0,0,0,0,$sWidth,$sHeight,$originalWidth,$originalHeight)) {
@imagejpeg($newImage, $smallLoc, 90);
}
}
else {
@imagejpeg($image, $smallLoc, 90);
}
}
}
if(($this->file == 'categories_image') && (strlen ($file['tmp_name']>0))) {
// Get The Image as a String
$pictureString = fread(fopen($file['tmp_name'], "rb"), $file['size']);
$image = imagecreatefromstring($pictureString);
// This validates whether or not a valid image was uploaded.
if ($image !== false) {
// Dimensions For The Uploaded Picture
$catWidth = 200;
$catHeight = 200;
// Set Current For All Sizes
$cWidth = $originalWidth = imagesx($image);
$cHeight = $originalHeight = imagesy($image);
// Small
if($cWidth > $catWidth) {
$cHeight = $cHeight / ($cWidth / $catWidth);
$cWidth = $catWidth;
}
if($cHeight > $catHeight) {
$cWidth = $cWidth / ($cHeight / $catHeight);
$cHeight = $catHeight;
}
if($cWidth != $originalWidth || $cHeight != $originalHeight) {
$newImage = imagecreatetruecolor($cWidth, $cHeight);
if(imagecopyresampled($newImage,$image,0,0,0,0,$cWidth,$cHeight,$originalWidth,$originalHeight)) {
@imagejpeg($newImage, $file['tmp_name'], 90);
}
}
else {
@imagejpeg($image, $file['tmp_name'], 90);
}
}
}
/* END CHANGE */
Hope it helps
Bookmarks