0

2つの画像があります。1つは、回転したポラロイドフレームのjpg画像ですpolaroid.jpg。もう1つは普通の画像image.jpgです。

画像を回転させてから、ポラロイド画像の上に配置して、マージされた画像を1つのjpg画像として表示しようとしています。

私は次のコードにかなり近いと思いますが、透明性を機能させることができません。回転した画像のカバーされていないゾーンは、透明ではなく黒です。私は何が間違っているのですか?トップ画像の背景を透明にするために関連する行にコメントを追加しました。

$bg_src = "polaroid.jpg";

$img_src = "image.jpg";

$outputImage = imagecreatefromjpeg($bg_src);

$img = imagecreatefromjpeg($img_src);

// This should create transparent background.
$bgd_color = imagecolorallocatealpha($img, 0, 0, 0, 127); 

// This should assign the transparent background to the uncovered zone after rotation
$img = imagerotate($img, 10, $bgd_color);

// This should make sure the alpha transparency gets saved
imagesavealpha($img, true);

$img_x = imagesx($img);

$img_y = imagesy($img);

imagecopymerge($outputImage,$img,156,50,0,0,$img_x,$img_y,100);

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

imagejpeg($outputImage);

imagedestroy($outputImage);
4

1 に答える 1

1

いくつかのヒーブ検索の後にそれを理解しました。本当にシンプルであることがわかりました。私はちょうどこの行を変更しました:

imagesavealpha($img, true);

これに:

imagecolortransparent($img,$bgd_color);

わーい!:)

于 2012-10-25T21:59:19.807 に答える