NYCPHP Meetup

[nycphp-talk] GD and image resizing

Aaron Fischer agfische at email.smith.edu
Wed Jan 31 17:48:52 EST 2007


Thanks Tedd and Dan.  This code and the archives link helped me  
understand what I needed to do.  I'm off and running and everything  
is working great.  Much appreciated!!

-Aaron	

On Jan 31, 2007, at 12:24 PM, tedd wrote:

> At 9:37 AM -0500 1/31/07, Aaron Fischer wrote:
>>
>> I'm under severe time constraints to have a project completed so  
>> if someone has some GD resize stuff to help me get going I would  
>> be most appreciative.  Tips/pointers are also helpful.
>

> If you already know the picture name and type, this will work.
>
> <?php
> // The file
> $filename = 'test.jpg';
> $outfilename = "/path/picture.jpg";
>
> // Set a maximum height and width
> $width = 200;
> $height = 200;
>
> // Get new dimensions
> list($width_orig, $height_orig) = getimagesize($filename);
>
> if ($width && ($width_orig < $height_orig))
>   {
>    $width = ($height / $height_orig) * $width_orig;
>   }
> else
>   {
>    $height = ($width / $width_orig) * $height_orig;
>   }
>
> // Resample
> $image_p = imagecreatetruecolor($width, $height);
> $image = imagecreatefromjpeg($filename);
> imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height,
> $width_orig, $height_orig);
>
> // Output
> imagejpeg($image_p, $outfilename, 100);
> ?>
>




More information about the talk mailing list