2
$c = 'johnny-bravo.png'; //transparent bg
$imagesize = getimagesize($c);

$background = imagecreatefrompng('background.png'); //background
$char = imagecreatefrompng($c);

imagealphablending($char, false);
imagesavealpha($char, true);

imagecopymerge($background, $char, 260, 17, 0, 0, $imagesize[0], $imagesize[1], 100);

header('Content-type: image/png');

imagepng($background);
imagedestroy($background);

Output:

https://i.stack.imgur.com/0E7Lz.png

How can I make transparent background to "johnny-bravo" ?

1 Answers1

0

use below code :

$c = 'johnny-bravo.png'; //transparent bg
$imagesize = getimagesize($c);

$tmp = @imagecreatetruecolor( $imagesize[0],  $imagesize[1] );
@imagealphablending( $tmp , false );
@imagesavealpha( $tmp , true );
$background = @imagecreatefrompng('background.png');

@imagecopyresampled( $tmp , $background , 0 , 0 , $imagesize[0] , $imagesize[1] , $imagesize[0] , $imagesize[1] );
$char = @imagecreatefrompng($c);
@imagecopyresampled($tmp , $char, 260, 17, 0, 0, $imagesize[0], $imagesize[1], 100);

header('Content-type: image/png');

imagepng($tmp);
imagedestroy($tmp);
DJafari
  • 12,955
  • 8
  • 43
  • 65
  • @Daniela Răducanu Test My Edited Code – DJafari Apr 01 '12 at 21:25
  • @Daniela Răducanu you must first create an image to your size, and use `imagealphablending` and `imagesavealpha` after, copy 2 images with `imagecopyresampled` on it, this is your solution, but because i can't access to php web server, can't give to you working code – DJafari Apr 01 '12 at 21:31