hi there, i could need an image resize script for php. i already have something that scales pictures down every time the page is requested, but it needs to much resources. and im running out of memory if i try to scale down a 6megapixel camera image down to 1280x1024 (its a 4 or 8mb memory limit for scripts at my server i think). so i need something that loads the picture, scales it down to 1280x1024 and saves the result as a new .jpg-file. good quality would be also nice, what i get at the moment dosnt looks a bit cheap. has someone already done something like this?
You can get the code you need from: www.php.net/imagecopyresampled Plenty of thumbnailers and resizers have been posted in the comments for that tag as well as imagecopyresized and imagecreatefromjpeg.
Did you try php classes? http://www.phpclasses.org/ You are doing the right thing by making the changes ya want. Resizing images on the fly is a no no in almost all cases.
he you guys are fast! i tryed google before, but only got heaps of windows/linux/mac image resizing software because they had a ".php" in adress ...
You can alter the memory usage for your script using ini_set. ini_set("memory_limit","32M"); PHP: Gives 32Mb memory.
$imageinfo = getimagesize($filelocation); if (function_exists('memory_get_usage') && memory_get_usage() + $memoryNeeded > (integer) ini_get('memory_limit') * pow(1024, 2)) { ini_set('memory_limit', (integer) ini_get('memory_limit') + ceil(((memory_get_usage() + $memoryNeeded) - (integer) ini_get('memory_limit') * pow(1024, 2)) / pow(1024, 2)) . 'M'); } PHP: I pulled this from php.net; automatically adjusts memory needed based on size of the image.
Maybe bandwidth is not an issue for you. But I'm thinking, as easy as it is to install and or use the built in widows XP image resizer and as fast as it is, wouldn't your users have a better experience if they resized to 1024x768 before upload? I got bikers with propane powered computers that can do it, I'm sure someone who plays with a 6Mpixel digital cam could handle it. Just a suggestion. As for coding a resizer, there is more then one way to skin a cat, all of the above ideas apply. But putting them together for your app is a bit harder to concieve then to suggest them.
Sorry for digging this up but I thought better have some useful answer for visitors who have searched through Google to here. Below is it: Well not just imagecopyresampled. You need 5 different php functions from gd extension to achieve an image resize. This PHP image resizer class takes an original image file as input, resizes it by your given new width (or height) and stores the resized data to a new file / replaces the old file, doing just what he needs.