GDで透かしを追加

//ヘッダーでimg画像であることを宣言
header("Content-Type: image/png");
//画像の読み込み
$dest = imagecreatefrompng('sample.png');
$src = imagecreatefrompng('watermark.png');

//元画像の幅と高さを取得
$dest_w = imagesx($dest);
$dest_h = imagesy($dest);

//透かしの幅と高さを取得
$src_w = imagesx($src);
$src_h = imagesx($src);

//透かしを表示する座標(画像の真ん中)
$dest_x = $dest_w/2-$src_w/2;
$dest_y = $dest_h/2-$src_h/2;


//画像を合成
//(画像リンク,透かしリンク,x座標,y座標,透かしx座標,透かしy座標,画像の幅,高さ,アルファ)
imagecopymerge($dest,$src,$dest_x,$dest_y,0,0,$src_w,$src_h,4);

//書き出し
imagepng($dest);

参考にしたサイト

  • http://www.phppro.jp/phpmanual/php/function.imagecopymerge.html
  • http://symfoware.blog68.fc2.com/blog-entry-861.html
  • http://php.net/manual/ja/function.imagecopymerge.php