|
Posted by SrSilveira on 06/14/07 01:25
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]
|