1

PHPコードで作成した画像に背景画像として画像を追加したい

<?php
header('Content-type: image/gif');
// Fetch GET params
$mode = isset($_GET["mode"]) ? strip_tags($_GET["mode"]) : "big";
$url = isset($_GET["text"]) ? $_GET["text"] : "This is an Invalid Code";

// Get size depending on mode
$size = ($mode && $mode == "small") ? "36" : "200";
// Get chart data. Limit data length if mode is small
$chl = ($mode && $mode == "small") ? substr($url, 0, 33) : $url;
// Assemble chart image URL
$imgUrl = "http://chart.apis.google.com/chart?chs=" . $size . "x" . $size . "&cht=qr&chld=H|0&chl=" . $chl;

// Load, transform and write transparent QR code image
$im = imagecreatefrompng($imgUrl);
imagetruecolortopalette($im, false, 2);
$white = imagecolorclosest($im, 0, 0, 0);
imagecolortransparent($im, $white);
imagegif($im);
imagedestroy($im);
?>

画像は同じサーバー上にあります

http://www.example.com/img/sitebg.png

私が試したこと

<?php
header('Content-type: image/gif');
// Fetch GET params
$mode = isset($_GET["mode"]) ? strip_tags($_GET["mode"]) : "big";
$url = isset($_GET["text"]) ? $_GET["text"] : "This is an Invalid Code";

// Get size depending on mode
$size = ($mode && $mode == "small") ? "36" : "200";
// Get chart data. Limit data length if mode is small
$chl = ($mode && $mode == "small") ? substr($url, 0, 33) : $url;
// Assemble chart image URL
$imgUrl = "http://chart.apis.google.com/chart?chs=" . $size . "x" . $size . "&cht=qr&chld=H|0&chl=" . $chl;

// Load, transform and write transparent QR code image
$im2 = imagecreatefrompng("http://www.example.com/example/img/BG.png");
$im = imagecreatefrompng($imgUrl);
imagetruecolortopalette($im, false, 2);
$white = imagecolorclosest($im, 0, 0, 0);
imagecolortransparent($im, $white);

// Merge the stamp onto our photo with an opacity (transparency) of 50%
imagecopymerge($im, $im2);

// Save the image to file and free memory
imagepng($im);
//imagegif($im);
imagedestroy($im);
?>
4

1 に答える 1

4

bg画像の上にグラフを描きたいですよね?

次に、bijを開始して、背景画像から画像オブジェクトを作成し、コマンドを使用してそれをグラフとマージしますimagecopymerge()

  1. bg画像で画像オブジェクトを作成する
  2. 新しい画像オブジェクトとしてpngグラフを作成する
  3. それらをマージします
  4. 公演

使用方法の例を次に示します。クリックしてください。

于 2012-07-13T11:16:16.747 に答える