galvin Posted October 25, 2011 Share Posted October 25, 2011 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. } Quote Link to comment https://forums.phpfreaks.com/topic/249749-resizing-images-not-worth-it/ Share on other sites More sharing options...
Psycho Posted October 25, 2011 Share Posted October 25, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/249749-resizing-images-not-worth-it/#findComment-1281954 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.