2015-04-25 28 views
1

我已經嘗試了幾次,但我似乎無法得到透明背景腓添加居中文本圖像

任何建議這個圖片文字底部的2線爲中心?

<?php 
$filePath = "adopt.png"; //full path to your png, including filename and extension 

$img = @imagecreatefrompng($filePath); 
$width = imagesx($img); 
$height = imagesy($img); 

//create new image and fill with background color 
$backgroundImg = @imagecreatetruecolor($width, $height); 
imagecopy($backgroundImg, $img, 0, 0, 0, 0, 100, 130); 
$color = imagecolorallocatealpha($backgroundImg, 0, 0, 0, 127); //fill transparent back 

imagefill($backgroundImg, 0, 0, $color); 

//save as png 

header("Content-type: image/png"); 
imagepng($backgroundImg); 
imagedestroy($backgroundImg);  
?> 
+0

很高興看到您的嘗試代碼。 IT會澄清你想要做的事情。 –

+0

試圖在底部添加兩行居中文本。 –

+0

顯示我們已經嘗試過的代碼。 – billynoah

回答

0

該過程起作用。沒有你的代碼,我只能從手冊中反彈出你的例子。 http://php.net/manual/en/function.imagestring.php。但它的工作原理,我已經使用了圖像字符串函數。它接受文本的座標,所以我不明白爲什麼它不適合你。

<?php 
// Create a 100*30 image 
$im = imagecreate(100, 30); 

// White background and blue text 
$bg = imagecolorallocate($im, 255, 255, 255); 
$textcolor = imagecolorallocate($im, 0, 0, 255); 

// Write the string at the top left 
imagestring($im, 5, 0, 0, 'Hello world!', $textcolor); 

// Output the image 
header('Content-type: image/png'); 

imagepng($im); 
imagedestroy($im); 
?> 
+0

如果這對您有用,請將其打勾爲正確答案。謝謝 –