You are here: RE: [PHP] GIF instead of JPG.. « PHP « IT news, forums, messages
RE: [PHP] GIF instead of JPG..

Posted by Mike on 10/21/79 11:11

> 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
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация