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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.