Jump to content

Recommended Posts

I'm trying to combine 2 images, based on what the user chooses. There are 4 backgrounds, and 4 characters, and the user can choose which bkg and which character they want. I have a png of each of these 8 graphics. When the user chooses their combo, I have a working script that combines those two images together, but the alpha of the top png isn't coming through. It just put black pixels anywhere there was alpha other than 0 or 100.

I ended up just treating it like a transparent gif and selecting a color to be transparent, and it works great, but I'm getting jagged edges, and I would love the soft shadows I can get with an alpha png.

Here's my current php script:
[code]<?
header ("Content-type: image/png");
$background = imagecreatefrompng($_POST['bkg']);
$overlay = imagecreatefrompng($_POST['char']);
imagecolortransparent($overlay,imagecolorat($overlay,0,0));
$insert_x = imagesx($overlay);
$insert_y = imagesy($overlay);
imagecopymerge($background,$overlay,0,0,0,0,$insert_x,$insert_y,100);
imagepng($background);
?>[/code]

I've seen transparency functions within gd that seem to allow use of the alpha of the png, but I can't get them to work with imagecopymerge. I'm sure it's me doing something wrong, but I don't know what. I hope my explanation above is clear.

Anyone here have an idea of how I can accomplish this.

Thanks,
Dan
Link to comment
https://forums.phpfreaks.com/topic/15731-gd-transparent-png-question/
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.