Reply to Re: [PHP] GIF instead of JPG..

Your name:

Reply:


Posted by Andras Kende on 10/15/82 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?
>
> 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
>
>



Hello Ryan,

Im using the code below and works fine ...

Best regards,

Andras Kende
http://www.kende.com

//////////////////////////////////


<?php
function resample($src, $srcdir, $destdir, $width = '', $height = '')
{
if( is_file( $destdir . $src ) )
{
$src = $src; return;
}
$size = GetImageSize($srcdir . $src);
if (!$size[0] || !$size[1]) return;

$scale = min($width/$size[0], $height/$size[1]);
if ( $scale == 1 ) return;

$newwidth = (int)($size[0]*$scale);
$newheight = (int)($size[1]*$scale);
$xpos = (int)(($width - $newwidth)/2);
$ypos = (int)(($height - $newheight)/2);


$format = ereg_replace(".*\.(.*)$","\\1",$src);
$format = strtoupper($format);


if ($format == "JPG")
{
$destImg = ImageCreateTrueColor($width, $height);
$backColor=ImageColorAllocate($destImg, 255, 255, 255);
ImageFilledRectangle($destImg, 0, 0, $width, $height, $backColor);
$sourceImg = ImageCreateFromJPEG ($srcdir . $src);
ImageCopyResampled($destImg, $sourceImg, $xpos, $ypos, 0, 0, $newwidth,
$newheight, $size[0], $size[1]);
imagejpeg($destImg, $destdir . $src, 90);
}
elseif ($format == "GIF")
{
$destImg = ImageCreateTrueColor($width, $height);
$backColor=ImageColorAllocate($destImg, 255, 255, 255);
ImageFilledRectangle($destImg, 0, 0, $width, $height, $backColor);
$sourceImg = ImageCreateFromGIF ($srcdir . $src);
ImageCopyResampled($destImg, $sourceImg, $xpos, $ypos, 0, 0, $newwidth,
$newheight, $size[0], $size[1]);
imagegif($destImg, $destdir . $src, 90);
}

}
?>

//////////////////////////////////

[Back to original 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

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