johnsmith153 Posted August 23, 2010 Share Posted August 23, 2010 I have used the same method for uploading photos for ages but feel there may be a better way. For both methods, please assume all uploads are large digital camera uploads of a few megabytes and thousands of pixels wide (as you would expect from large digital camera images). CURRENT METHOD (1) receive uploaded file and use ImageMagick to convert to 4 file sizes, then store these file sizes (also set so ImageMagick reduces the quality to something like a setting of 80 out of 100 which will further reduce file size. - file sizes (widths): 800 240 120 60 (mobile phones etc.) (2) Based on the type of size and view required I then use <img src="/photos/240/file.jpg to display (240 being the required image size of course) POSSIBLE BETTER METHOD (1) Use ImageMagick to reduce to 800 wide as will never display bigger than this anyway, reduce quality also. But don't resize further and only need one file. (2) Use PHP commands to display an image, and set height/width/quality then. Eg: <img src="showImage.php?file=file.jpg&width=240&quality=60 So both would do the same thing but the second seems better as you don't need to create 4 images for every photo upload. Why make lots of thumbnails when you can make one and then get PHP to create at the time of display? Although I suppose if you regularly displayed these images in a search result then PHP would need to do that extra processing on every search. Creating all 4 at the time of upload only requires the one bit of processing. Have I just found the answer? Quote Link to comment https://forums.phpfreaks.com/topic/211524-photo-upload-very-basic/ Share on other sites More sharing options...
litebearer Posted August 23, 2010 Share Posted August 23, 2010 yep. less server load and less load time using pre-sized Quote Link to comment https://forums.phpfreaks.com/topic/211524-photo-upload-very-basic/#findComment-1102791 Share on other sites More sharing options...
DavidAM Posted August 23, 2010 Share Posted August 23, 2010 The difference will be in bandwidth used and browser processing. When you set the width and or height of an IMG tag, that ONLY changes the way it displays (the browser has to shrink or stretch the image) it does NOT change the amount of data sent to the browser. So, if you use a single image, and let's just say it is 1.4MB, then it will ALWAYS transfer 1.4MB from the server to the browser regardless of how big the browser displays it. This is a lot of data for slow connections, and chews up your bandwidth allowance (if your hosting plan has a limit). If you resize the images on upload, you are using server CPU time (once) and disk space for storage, but then when you send an image to the browser, you are sending less data (using less bandwidth) with the "60" size than with "800" size. Quote Link to comment https://forums.phpfreaks.com/topic/211524-photo-upload-very-basic/#findComment-1102793 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.