1

Im using php code to merge user image on png background. Here below is code i am use.

$width = 140; 
$height = 140; 
$bottom_image = imagecreatefrompng("bg.png"); 
$top_image = imagecreatefromjpeg("default.jpg"); 
imagesavealpha($top_image, true); 
imagealphablending($top_image, false); 
imagecopyresampled($bottom_image, $top_image, 290, 125, 0, 0, $width,     $height, $width, $height);
//imagecopy($bottom_image, $top_image, 290, 125, 0, 0, $width, $height); 
header('Content-type: image/png');
imagepng($bottom_image);

but i got this result when i save image

i want user image in round circle back.

Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103

1 Answers1

1

You are copying a JPEG image over the background image.

JPEG doesn't support transparency.

What you could do with the gd library is:

  • Create a new result image of the desired size, then
  • Copy the JPEG (user picture) to its center, then
  • Copy the partially-transparent PNG background (actually foreground) over result image. The PNG background must have a "transparent window" in the middle so that the user picture doesn't get hidden behind the background (in other words, the white circle part of the background must be transparent).
Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103