BossHoss
April 22nd, 2003, 03:06 AM
Something that is missing in squirrelcart is the control of the product images. Instead of allowing cart users to upload the images without having done any resizing to them, you might consider running the image through a function like "snashot" below. The cart user sets the pixel width ($X1) for the image they want to use for say the thumbnail, then on upload/update (GD library restricted to jpg & png since dropping gif due to patent issues) the script will actually resize images so that a 800x600 image a client uploads as a "thumbnail" will fit in the layout.
The advantage to this is that the image is not just resized to width="X1" pixels during serving to client, but the image itself is sized to "X1" pixels removing distortion of the image and also reduces the actual memory required usually 3:1 - 5:1 factor.
The pixel width of the different images can actually be set in the General Cart Settings. This way you don't have different thumbnail image sizes strewn through out your products. This would help make a pro out of any cart user.
I'm using the following function in a classified web application I integrated with your squirrelcart..to make sure the image uploaded for the used saddle fits properly in the view layout.
http://www.dutchessbridlesaddle.com/used_saddles/
//used to take whatever client uploads and set to desired x-axis width (X1) for memory considerations.
function snapshot($filename,$dir,$destination,$X1,$kill) {
if(file_exists($dir.$filename)) {
$extension = @explode(".",$filename);
if ($extension[1]=="jpg" or $extension[1]=="JPG") { $img = imagecreatefromjpeg($dir.$filename);}
else if ($extension[1]=="png" or $extension[1]=="PNG") { $img = imagecreatefrompng($dir.$filename); }
else { echo "File format must be of type jpg, or png format.<br>"; return;}
$imgsz = getimagesize($dir.$filename);
$ratio = $imgsz[0]/$X1;
$Y1 = $imgsz[1]/$ratio;
$snapshot = imagecreate($X1,$Y1);
imagecopyresized($snapshot,$img,0,0,0,0,$X1,$Y1,$i mgsz[0],$imgsz[1]);
if ($extension[1]=="jpg" or $extension[1]=="JPG") { imagejpeg($snapshot,$dir.$destination);}
else if ($extension[1]=="png" or $extension[1]=="PNG") { imagepng($snapshot,$dir.$destination); }
imagedestroy($img);
imagedestroy($snapshot);
if ($kill=="1") { unlink($dir.$filename); }
} else { echo "File does not appear to be uploaded: ".$dir.$filename."<br>";}
}
The advantage to this is that the image is not just resized to width="X1" pixels during serving to client, but the image itself is sized to "X1" pixels removing distortion of the image and also reduces the actual memory required usually 3:1 - 5:1 factor.
The pixel width of the different images can actually be set in the General Cart Settings. This way you don't have different thumbnail image sizes strewn through out your products. This would help make a pro out of any cart user.
I'm using the following function in a classified web application I integrated with your squirrelcart..to make sure the image uploaded for the used saddle fits properly in the view layout.
http://www.dutchessbridlesaddle.com/used_saddles/
//used to take whatever client uploads and set to desired x-axis width (X1) for memory considerations.
function snapshot($filename,$dir,$destination,$X1,$kill) {
if(file_exists($dir.$filename)) {
$extension = @explode(".",$filename);
if ($extension[1]=="jpg" or $extension[1]=="JPG") { $img = imagecreatefromjpeg($dir.$filename);}
else if ($extension[1]=="png" or $extension[1]=="PNG") { $img = imagecreatefrompng($dir.$filename); }
else { echo "File format must be of type jpg, or png format.<br>"; return;}
$imgsz = getimagesize($dir.$filename);
$ratio = $imgsz[0]/$X1;
$Y1 = $imgsz[1]/$ratio;
$snapshot = imagecreate($X1,$Y1);
imagecopyresized($snapshot,$img,0,0,0,0,$X1,$Y1,$i mgsz[0],$imgsz[1]);
if ($extension[1]=="jpg" or $extension[1]=="JPG") { imagejpeg($snapshot,$dir.$destination);}
else if ($extension[1]=="png" or $extension[1]=="PNG") { imagepng($snapshot,$dir.$destination); }
imagedestroy($img);
imagedestroy($snapshot);
if ($kill=="1") { unlink($dir.$filename); }
} else { echo "File does not appear to be uploaded: ".$dir.$filename."<br>";}
}