2012-07-13 39 views
0

我想的图像作为背景图像添加到由我的PHP代码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); 
?> 

回答

2

你要牛逼o在bg图像上绘制图形的权利?

然后,只需开始bij从背景图像创建图像对象,然后使用命令imagecopymerge()将其与图形合并。

  1. 创建图像对象与背景图片
  2. 创建PNG图形作为新的图像对象
  3. 合并在一起,
  4. 显示

下面是一个例子,如何使用它:click!

+0

我试过了,它使图像没有显示 – RussellHarrower 2012-07-13 11:27:31

+1

你试过服务器上的示例代码吗? – 2012-07-13 11:28:18