RE: GIF instead of JPG..

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Hi,
> I found this beautiful piece of code on the php site which 
> make a proportional thumbnail, problem is its only working 
> with JPEG files...and not with GIFs, can someone please help 
> me convert it to GIF too?
> 

If your version of GD supports GIFs (which not all do), then it's almost as
simple as changing every place you see the string "jpeg" to "gif". 

Look in the online manual for the image functions. You'll see reference to
the ones here (such as imagecreatfromjpeg()) and also ones for PNGs and GIFs
and a few others.

Just realize that when you are reading a file of a particular type, you need
to use those image<type>() functions... But in most cases they are
completely interchangable if you're passing paths to images of the
appropriate type.

Hope all of that makes sense :)

-M


> I tried but got a bit confused as there are no functions that 
> are equal to "imagecreatetruecolor" that is in the below script.
> The below script works perfectly for jpgs:
> 
> 
> <?php
> // The file
> $filename = 'test.jpg';
> 
> // Set a maximum height and width
> $width = 200;
> $height = 200;
> 
> // Content type
> header('Content-type: image/jpeg');
> 
> // 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, null, 100);
> ?>
> 
> 
> Beautiful, isnt it? Hats off to whoever wrote it and three 
> cheers for the online manual!
> 
> Thanks,
> Ryan
> 
> 
> 
> 
> 
> 
> 
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.308 / Virus Database: 266.8.0 - Release Date: 3/21/2005
> 
> --
> PHP General Mailing List (http://www.php.net/) To 
> unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux