Hi Ash, Thanks for your suggestion. I think this is where my confusion is. I understand how to use imagecolorallocatealpha() to for example create a 50% transparant colour, and apply it to a new rectangle for example.
I dont understand how to "apply" it to a new source image, for example $src = imagecreatefrompng('test.png'); // Something here (maybe imagecolorallocatealpha()) to make this 50% transparent- either on its own, or make it 50% transparent as part of a copy onto a new image I had thought that imagecopymerge would help me with this, but it seems not. I'm currently looking through Karl's example to see if I can work it out, but if anyone can point out a super-simple way of achieving the pseudo-code above, i'd be very grateful! Cheers, Alex On Thu, May 13, 2010 at 1:34 AM, Ashley Sheridan <a...@ashleysheridan.co.uk>wrote: > On Thu, 2010-05-13 at 00:12 +0100, Alex Davies wrote: > > Hi, > > 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 from the > HTML page. > > If I set the opacity to 0, everything works - I end up with a transparant > image. > > 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 goes up > 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: > > <?php > $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 > imagecolortransparent($dest, $trans_colour); > //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 > header('Content-Type: image/png'); > imagepng($dest); > ?> > > The images that this outputs, at opacity levels 0,1 and 80 on a red and > green background (screenshots of a HTML page) can be downloaded > fromhttp://www.box.net/shared/h9zn4tjgro > > Any help appreciated! > > Cheers, > > Alex > > > How exactly are you setting the opacity for the image? The traditional way > is to use imagecolorallocatealpha() on the source. > > Thanks, > Ash > http://www.ashleysheridan.co.uk > > > -- Alex Davies This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender immediately by e-mail and delete this e-mail permanently.