Transparency PNG with PHP

Hey, having some problems trying to maintain transparency in png when I create a sketch from it, can anyone work on this? any help would be great, here is what i am doing now:

$fileName= "../js/ajaxupload/tees/".$fileName; list($width, $height) = getimagesize($fileName); $newwidth = 257; $newheight = 197; $thumb = imagecreatetruecolor($newwidth, $newheight); imagealphablending($thumb, true); $source = imagecreatefrompng($fileName); imagealphablending($source, true); imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagesavealpha($thumb, true); imagepng($thumb,$newFilename); 
+43
php transparency png
Nov 23 '08 at 22:59
source share
5 answers

I have had success doing this in the past:

 $thumb = imagecreatetruecolor($newwidth, $newheight); imagealphablending($thumb, false); imagesavealpha($thumb, true); $source = imagecreatefrompng($fileName); imagealphablending($source, true); imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagepng($thumb,$newFilename); 

I found the quality of the output image much better using imagecopyresampled() than imagecopyresized()

+81
Nov 23 '08 at 23:23
source share

Forget about the color transparency index, it never works in all rendering products. Use an alpha layer mask instead:

 $image = imagecreatetruecolor($size, $size); imagealphablending($image, false); imagesavealpha($image, true); $trans_layer_overlay = imagecolorallocatealpha($image, 220, 220, 220, 127); imagefill($image, 0, 0, $trans_layer_overlay); 
+14
Feb 22 '11 at 20:59
source share

imagecopyresized does not support transparency.

imagecopymerge , but it does not change.

Decision? You are probably probably manually resizing.

+2
Nov 23 '08 at 23:12
source share

These features access the gdlib core library, which is a great toy, but not something that does good results. If you have an option, use imagemagick . The downside is that there are currently no good php bindings, so you need to access it through a shell that is usually not allowed on shared hosts.

+2
Nov 23 '08 at 23:32
source share

See dycey's answer to the question "How to resize ..." . Essentially, before you perform any other operations, you need to fill the entire background with transparency.

+1
Nov 23 '08 at 23:06
source share



All Articles