Re: Scaling image is losing background transparency [message #171664 is a reply to message #171660] |
Fri, 14 January 2011 23:12 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma:
|
Senior Member |
|
|
laredotornado(at)zipmail(dot)com wrote:
> I'm using PHP 5 and trying to scale png images programatically. Here
> is what I'm doing ...
>
> $src_img = imagecreatefrompng($imagefile);
> $hw = getimagesize($imagefile);
> $new_w = $w;
> $new_h = $hw["1"]/($hw["0"]/$w);
> $dst_img = @imagecreatetruecolor($new_w, $new_h);
> if(!$dst_img) {
> $dst_img = imageCreate($new_w, $new_h);
> }
> imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,
> $new_h,imagesx($src_img),imagesy($src_img));
> imagepng($dst_img);
>
> The problem is my scaled png image loses its background transparency.
> The short of this is, does anyone know how to scale PNG images
> effectively and what other information can I provide to help
> troubleshoot this further?
I suppose it can be done with the GD library (which you are using), but you
need to preserve the pixels' alpha channel value (that which you misnamed
"background transparency"). There is an imagesavealpha() function that
looks promising.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
|
|
|