I have a php file I made just a few months ago.
It takes a gif, jpeg or png of any size and sizes it proportionately
to a specified size and then outputs a png.
If the image is a transparent png or transparent gif, it will still
hold the transparency.
This is just a test page and it tested ok for me, but it is my first
one. I also tested it on PHP 5. Dont know about compatibility to
Knowing that, here you go.
On May 12, 2010, at 6:12 PM, Alex Davies wrote:
I am trying to import a PNG image from disk, place it on top of a
transparant image created in GD and output it to the browser. In
the case of
a low opacity setting, I would expect to see the background colour
If I set the opacity to 0, everything works - I end up with a
However, if I set it for any value >0 (even 1) instead of a
very-faint-image the whole thing goes black. As the opacity level
from 0, the amount of black reduces and the amount of imported image
increases - but this is not what I want.
I am using this code:
$src = imagecreatefrompng('test.png');
$img_width = imagesx($src);
$img_height = imagesy($src);
// Create trans image
$dest = imagecreatetruecolor($img_width, $img_height);
//imagesavealpha($dest, true); // This has no effect it appears
$trans_colour = imagecolorallocatealpha($dest, 0, 255, 0, 128);
// Make the background transparent
//imagefill($dest, 0, 0, $trans_colour); // This does not work
// Merge src on top of dest, with opacity of 1 in this case
imagecopymerge($dest, $src, 0, 0, 0, 0, $img_width, $img_height, 1);
// Output and free from memory
The images that this outputs, at opacity levels 0,1 and 80 on a red
green background (screenshots of a HTML page) can be downloaded from
Any help appreciated!
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php