Jump to content

merge 2 GD images with alpha


The Little Guy

Recommended Posts

I have 2 GD images, one is a JPG, the other is a gd created image.

 

<?php
header("content-type: image/png");

$img = imagecreatefromjpeg("./real/soldier.jpg");

$img2 = imagecreatetruecolor(300, 300);
imagesavealpha($img2, true);
$color = imagecolorallocatealpha($img2, 255, 0, 0, 75);
imagefill($img2, 0, 0, $color);

$final = imagecreatetruecolor(300, 300);
imagecopymerge($final, $img, 0, 0, 0, 0, 300, 300, 100);
imagecopymerge($final, $img2, 0, 0, 0, 0, 300, 300, 100);


imagepng($final, null, 9);

 

I am trying to place the gd created image (Red image) on top of the other (soldier.jpg), but for some reason I can not figure out why the red is a solid red when I told it to have transparency to it (75).

 

So basically how do I create images like this with saved alpha?

Link to comment
https://forums.phpfreaks.com/topic/259651-merge-2-gd-images-with-alpha/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.