2016-03-28 8 views
1

私はpngの背景にユーザー画像をマージするPHPコードを使用しています。ここで私は使用しているコードです。 どのように背景画像上の画像をマージする

but i got this result when i save image

$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); 

は、私は戻って丸い円の中にユーザ画像をしたいです。

+0

http://stackoverflow.com/questions/999251/crop-or-mask-an-image-into-a-circle/999563#999563 – C2486

答えて

1

背景画像にJPEG画像をコピーしています。

JPEGは透過性をサポートしていません。あなたはGDライブラリで何ができるか

は次のとおりです。

  • 、その後、所望の大きさの新しい結果画像を作成してコピーJPEG(ユーザー写真)を中心に、その後、
  • 部分的に透明なPNG背景(実際には前景)を結果イメージにコピーします。 PNG背景は、ユーザーの写真が背景の背後に隠れないように(つまり、背景の白い円の部分が透明でなければならないように)中間に「透明なウィンドウ」を持つ必要があります。
+0

ありがとう@ alex-shesterovその作業!!! –

+0

よろしくお願いいたします。喜んで助けてください。 –