note 71091 added to function.imagecreatefrompng

From: Date: Sat, 11 Nov 2006 18:46:11 +0000
Subject: note 71091 added to function.imagecreatefrompng
Groups: php.notes 
Request: Send a blank email to php-notes+get-119610@lists.php.net to get a copy of this message
I had a problem with PNG files. My source files were PNG-8 files and i wanted to add some drawings to the Image with alpha blending, but it was not possible only by doing imagecolorallocatealpha() and imagefilledellipse() for example. I noticed that it was only working for PNG-24 images, but i don't want to use them, because they are to big for my website, but PNG-8 files would be much greater. My result is that the image has to be converted to PNG-24 after loading and converted back to PNG-8 before saving/output. This is the script: <?php // Load Image and get it's size $size = getimagesize("png8image.png"); $im = imagecreatefrompng("png8image.png"); // Convert the Image to PNG-24 $im_tc = imagecreatetruecolor($size[0],$size[1]); imagecopy($im_tc,$im,0,0,0,0,$size[0],$size[1]); imagedestroy($im); //Now do what ever you want, all alpha-operation do work $color = imagecolorallocatealpha ($im_tc,255,255,255,75); imagefilledellipse ($im_tc,10,10,6,4,$color); //And now convert it back to PNG-8 $im_result = imagecreate($size[0],$size[1]); imagecopy($im_result,$im_tc,0,0,0,0,$size[0],$size[1]); imagedestroy($im_tc); //And save it imagepng($im_result,"png8image.png"); ?> ---- Server IP: 192.35.244.50 Probable Submitter: 84.115.78.122 ---- Manual Page -- http://www.php.net/manual/en/function.imagecreatefrompng.php Edit -- https://master.php.net/note/edit/71091 Del: integrated -- https://master.php.net/note/delete/71091/integrated Del: useless -- https://master.php.net/note/delete/71091/useless Del: bad code -- https://master.php.net/note/delete/71091/bad+code Del: spam -- https://master.php.net/note/delete/71091/spam Del: non-english -- https://master.php.net/note/delete/71091/non-english Del: in docs -- https://master.php.net/note/delete/71091/in+docs Del: other reasons-- https://master.php.net/note/delete/71091 Reject -- https://master.php.net/note/reject/71091 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#119610) next »