You are here: Re: imagecopyresampled not working « PHP Programming Language « IT news, forums, messages
Re: imagecopyresampled not working

Posted by SrSilveira on 06/14/07 01:26

On Jun 13, 2:10 pm, "Bint" <b...@csgs.com> wrote:
> Hello,
>
> I'm trying to create thumbnails of PNG images. I have code that used to
> work but doesn't seem to anymore. The resizing just seems to return black
> images, even though my source image is not black. Anyone know what could be
> the problem?
>
> Here's my code:
>
> $width = imagesx($im);
> $height = imagesy($im);
>
> if ($width >= $height) {
> if ($width > 32)
> $thumbwidth = 32;
> else $thumbwidth = $width;
> $aspect = $width/$height;
> $thumbheight = $thumbwidth/$aspect;
> }
> else {
> if ($height > 32)
> $thumbheight = 32;
> else $thumbheight = $height;
> $aspect = $width/$height;
> $thumbwidth = $thumbheight*$aspect;
> }
>
> $tim = ImageCreateTrueColor($thumbwidth,$thumbheight);
>
> imagealphablending($tim, FALSE);
> imagesavealpha($tim, TRUE);
> $myBool = imagecopyresampled( $tim, $im, 0, 0, 0, 0, $thumbwidth,
> $thumbheight, $width, $height);

that works for me:

$im = "forest.png";

list($width, $height) = getimagesize($im);

if ($width >= $height) {
if ($width > 32)
$thumbwidth = 32;
else $thumbwidth = $width;
$aspect = $width/$height;
$thumbheight = $thumbwidth/$aspect;
}else {
if ($height > 32)
$thumbheight = 32;
else $thumbheight = $height;
$aspect = $width/$height;
$thumbwidth = $thumbheight*$aspect;
}

$tim = ImageCreateTrueColor($thumbwidth,$thumbheight);
$image = imagecreatefrompng($im);
imagealphablending($tim, FALSE);
imagesavealpha($tim, TRUE);
$myBool = imagecopyresampled($tim, $image, 0, 0, 0, 0, $thumbwidth,
$thumbheight, $width, $height);

header('Content-type: image/png');

imagepng($tim);

 

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

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