note 103274 added to function.imagecreatefrompng
| From: | denis at ryzhkov dot org | Date: | Tue, 05 Apr 2011 10:46:45 +0000 |
| Subject: | note 103274 added to function.imagecreatefrompng | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-178509@lists.php.net to get a copy of this message | ||
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!
?>
----
Server IP: 69.147.83.197
Probable Submitter: 178.121.13.235
----
Manual Page -- http://www.php.net/manual/en/function.imagecreatefrompng.php
Edit -- https://master.php.net/note/edit/103274
Del: integrated -- https://master.php.net/note/delete/103274/integrated
Del: useless -- https://master.php.net/note/delete/103274/useless
Del: bad code -- https://master.php.net/note/delete/103274/bad+code
Del: spam -- https://master.php.net/note/delete/103274/spam
Del: non-english -- https://master.php.net/note/delete/103274/non-english
Del: in docs -- https://master.php.net/note/delete/103274/in+docs
Del: other reasons-- https://master.php.net/note/delete/103274
Reject -- https://master.php.net/note/reject/103274
Search -- https://master.php.net/manage/user-notes.php