note 103274 deleted from function.imagecreatefrompng by danbrown
| From: | danbrown@php.net | Date: | Tue, 05 Apr 2011 15:08:10 +0000 |
| Subject: | note 103274 deleted from function.imagecreatefrompng by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-178517@lists.php.net to get a copy of this message | ||
Note Submitter: denis at ryzhkov dot org
----
Thanks for helping comments on imagecreatefrompng vs alpha.
Here is my working result, hope it will help somebody:
<?php
$png_fn = 'pal_bk.png'; // http://entropymine.com/jason/testbed/pngtrans/pal_bk.png
$png = imagecreatefrompng($png_fn);
// 1. direct
imagepng($png, 'result.png'); // has alpha!
// 2. with imagecopy
$png_size = getimagesize($png_fn);
$width = $png_size[0];
$height = $png_size[1];
$canvas = imagecreatetruecolor($width, $height);
imagesavealpha($canvas, true); // important
$max_alpha = imagecolorallocatealpha($canvas, 0, 0, 0, 127);
imagefill($canvas, 0, 0, $max_alpha); // important
imagecopy(
$canvas, $png,
0, 0,
0, 0, $width, $height
);
imagepng($canvas, 'result.png'); // has alpha!
?>