Jump to content

Resizing images not worth it?


galvin

Recommended Posts

I am using Amazon's S3 service to allow users to upload images.  Since you have to pay for this service, my plan was to resize all uploaded images (maybe to a max of 200 pixels wide or something) immediately before sending them to Amazon.

 

I googled this and only thing I found said that "resizing on the fly is slow and expensive because disk space is cheaper than CPU."  Is this accurate?

 

Anyone have any thoughts on this?  I feel like I have to restrict the size of images some way because I don't wan't people uploading huge 2000x2000 images.

 

In case it matters, below is some code I have used below for resizing (albeit on my own server), so I imagine I'll use something similar for this new project which ultimately sends the image to Amazon.

 

	// This is the temporary file created by PHP 
							$uploadedfile = $_FILES['userfile']['tmp_name'];

							// Create an Image from it so we can do the resize
							$src = imagecreatefromjpeg($uploadedfile);

							// Capture the original size of the uploaded image
							list($width,$height) = getimagesize($uploadedfile);

							$newheight=70;
							$newwidth= 70;

							$tmp=imagecreatetruecolor($newwidth,$newheight);

							// this line actually does the image resizing, copying from the original
							// image into the $tmp image

							imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); 

							// now write the resized image to disk. I have assumed that you want the
							// resized, uploaded image file to reside in the ./images subdirectory.

							$imagefolder = 'images/userimages/user' . $_SESSION['userid'] . '.jpg';
							$filename = $imagefolder;
							$_SESSION['filename'] = $filename;
							if (imagejpeg($tmp,$imagefolder,100)) {
								$imagemessage = "File is valid, and was successfully uploaded into FOLDER.\n";
								$success="yes";
								} else {
								$imagemessage = "Possible file upload attack!\n";
								$success="no";
								}
							imagedestroy($src);
							imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
							// has completed.

			}

Link to comment
Share on other sites

If you have a need to re-size the images, then by all means re-size them. It is up to you to decide what is worth your time, effort and cost. Not some blowhard that has a blog on the internet. But, that' snot to mean you don't get the proper information before your decision and reassess your decisions thereafter.

 

Go ahead and implement a resizing script then do some tests of images with sizes you think would represent what users may upload. Is the performance acceptable? Also, be sure to try very large images - ones that you think would be much, much bigger than would be submitted. At some point the process will probably fail. You should then set a maximum size that you will accept where performance is still acceptable and the process does not fail - and reject ones that are larger.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.