0

Possible Duplicate:
How to merge transparent PNG with image using PHP?

I am completely lost here, so help would be greatly appreciated. I am new to PHP image manipulation.

I have two semi-transparent png files, and I would like to overlay one over the other and output the resulting png.

Thanks in advanced.

EDIT:

  1. GD, though I can change that if needed.
  2. So far I've hacked this together from what I could find on the internet. It does not work.

Community
  • 1
  • 1
Alexander Rafferty
  • 6,134
  • 4
  • 33
  • 55

1 Answers1

1

imagecopymerge would be the solution

header("Content-Type: image/png");

$overlay = imagecreatefrompng("overlay.png");
$overlay_width = imagesx($overlay);
$overlay_height = imagesy($overlay);
$im = imagecreatefrompng("firstimage.png");
$width = imagesx($im);
$height = imagesy($im);
$dest_x = 0;
$dest_y = 0;
imagecopymerge($im, $overlay, $dest_x, $dest_y, 0, 0, $overlay_width, $overlay_height, 100);

imagepng($im);
Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107
  • Thanks, but the resulting image has a black background. – Alexander Rafferty Aug 03 '11 at 10:37
  • i just tried that and works perfectly, the images i was testing had transparent background .. the final image still has transparent background .. my php version is 5.2.10 with gd 2.0.34, maybe it's from your php version .. – Mihai Iorga Aug 03 '11 at 10:49