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

Posted by Richard Lynch on 09/29/26 11:11

On Wed, March 23, 2005 5:30 am, Ryan A said:
> 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?
>
> I tried but got a bit confused as there are no functions that are equal to
> "imagecreatetruecolor" that is in the below script.

I believe all the imagecreatefromXYZ functions create a truecolor image
for internal manipulation...

Though I could be wrong, as GIF images do have pallet information within
them, and I supposed GD could be justified in using that to build a
256-color image...

At any rate, imagecreatetruecolor creates a "format-less" image -- It's
not a GIF, JPEG, TIFF, or anything, really. It's in an internal GD
format, and you can do whatever you want to it, and then output it as
whatever format you want.

> The below script works perfectly for jpgs:

As noted, just change jpg to gif everywhere, and it should work fine, if
your GD supports GIF.

Or you could even alter the script to determine the image format based on
its filename, then call the correct imagecreatefromXYZ and the correct
imageXYZ at the end.

Or, you could even use http://php.net/imagegetsize and IGNORE the
filename, and base your decision on what's actually *IN* the file, so when
some idiot renames a jpeg to ".gif" because they think that will make it a
GIF (yes, that really happens) then you won't get messed up.

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


--
Like Music?
http://l-i-e.com/artists.htm

 

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

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