PDA

View Full Version : [ADDED] v1.3.0 - Image Size Routine to set Size



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>";}

}

wermo
May 9th, 2003, 05:21 PM
Hi Boss Hoss,

I really like that functionality. We have a client who does not know too much about computers so they basicaly will be taking pictures with digital camera and then uploading them.

Having a little routine that would automatically resize would be great. I'd like to put the routine for all three of these just in case she tries to upload a huge picture.

1) Thumbnail
2) Main Pictures

Can a kind soul point me to the right locations where these uploads occur? I could then integrate a routine to resize it just prior to the filename being stored in the database, etc (or however it is done).

This would be greatly appreciated!

Thanks,
wermo

BossHoss
May 9th, 2003, 05:46 PM
If Jamie will allow I can tell you what code file to modify..the function above needs to be included and then the snapshot call takes the filename passed to it through the admin page and then does the magic. You wouldn't have to actually set any image widths in the store pages, just control it at upload.

I'm surprised Jamie hasn't responded about this, but then again in the last release he actually did implement a lot of the suggestions.

realize the only downside is that this limits the image upload to jpg or png..if they have gif, bmp, tiff etc. then it won't work. This isn't a problem for me the designer, however for my client it might be.

wermo
May 9th, 2003, 09:11 PM
Cool would be helpful. I wrote some minor PHP programs here and there and some included resizing functionality, I was actually a little surprised that this cart didn't have it as it has so many other features.

I guess I could search through the routines themselves to find it if necessary but it'd be helpful to get some direction on it.

I see this as an excellent future addition to the program.

This will allow people who are not very computer literate to be able to upload pictures without having to worry about resizing prior to doing this (which many would not know how to do anyway).

My goal is to give our clients the ability to update their products themselves, and having an auto-resizer on uploads would make my life a whole lot easier :)

Thanks for the quick reply!
wermo

tealnet
October 6th, 2003, 01:39 AM
After just purchasing Squirrelcart, I am surprised to find such a simple feature missing. I have built this functionality into many sites I have developed. It only takes a few lines of code. It appears this thread has not been responded to by any support or development staff. Is this something that is planned for inclusion in the next release?

Jamie
October 6th, 2003, 12:13 PM
Yes, this is in the works. We have another post that we added prior to this one for the same functionality.

Jamie
November 24th, 2003, 11:13 AM
This functionality has been added to v1.3.0, which was just released. I am placing a post in the announcements section to discuss this and other image field improvements.

-Jamie