1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

image resize with php?

Discussion in 'PHP' started by falcondriver, Mar 30, 2006.

  1. #1
    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?
     
    falcondriver, Mar 30, 2006 IP
  2. TheHoff

    TheHoff Peon

    Messages:
    1,530
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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.
     
    TheHoff, Mar 30, 2006 IP
    falcondriver likes this.
  3. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #3
    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.
     
    noppid, Mar 30, 2006 IP
    falcondriver likes this.
  4. falcondriver

    falcondriver Well-Known Member

    Messages:
    963
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    145
    #4
    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 ...
     
    falcondriver, Mar 30, 2006 IP
  5. TheHoff

    TheHoff Peon

    Messages:
    1,530
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    0
    #5
    TheHoff, Mar 30, 2006 IP
  6. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You can alter the memory usage for your script using ini_set.

    ini_set("memory_limit","32M");
    PHP:
    Gives 32Mb memory.;)
     
    mad4, Mar 31, 2006 IP
  7. TheHoff

    TheHoff Peon

    Messages:
    1,530
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    0
    #7
    $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.
     
    TheHoff, Mar 31, 2006 IP
  8. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #8
    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.
     
    noppid, Mar 31, 2006 IP
  9. yangyang

    yangyang Banned

    Messages:
    757
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    0
    #9
    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.
     
    yangyang, Jan 15, 2009 IP