2012-07-13 43 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