Jump to content

Combining PNG Images with Transparency


Shadow Jolteon

Recommended Posts

Hello. :)

 

My friend and I have been trying to combine two PNG format images using this:

<?php
$background = htmlspecialchars($_GET['bg']);
$avatar = htmlspecialchars($_GET['av']);

$av = imagecreatefrompng('img/avatars/'.$avatar.'.png');
$bg = imagecreatefrompng('img/avatars/backgrounds/'.$background.'.png');

$sx = imagesx($av);
$sy = imagesy($av);

imagecopy($bg, $av, imagesx($bg) - $sx - $marge_right, imagesy($bg) - $sy - $marge_bottom, 0, 0, imagesx($av), imagesy($av));

header('Content-type: image/png');
imagepng($bg);
imagedestroy($bg);
?>

Everything works fine, except the transparency of the image is lost. I was just wondering if there is anyone here who knows how to fix this problem.

 

Thanks! :)

Link to comment
https://forums.phpfreaks.com/topic/137302-combining-png-images-with-transparency/
Share on other sites

i have had the same problem. i used the following code right after i imagecopy'ed them together. depending on gd versions, etc, it may work...

 

# Turn off alpha blending and set alpha flag
imagealphablending($bg, false);
imagesavealpha($bg, true);

 

if it doesn't work, i may help to debug further.

i have had the same problem. i used the following code right after i imagecopy'ed them together. depending on gd versions, etc, it may work...

 

# Turn off alpha blending and set alpha flag
imagealphablending($bg, false);
imagesavealpha($bg, true);

 

if it doesn't work, i may help to debug further.

Awesome, that worked. Thank you very much for your assistance! :)

 

Thanks to you, too, xtopolis. ^^

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.