2014-10-17 31 views
0

我需要使用imagepng中的圖像中的文本& imagettftext函數在PHP中。PHP imagettftext center text

這裏是我的代碼:

include "config.php"; 
header('Content-type: image/png'); 
function between($src,$start,$end){ 
    $txt=explode($start,$src); 
    $txt2=explode($end,$txt[1]); 
    return trim($txt2[0]); 
} 
$actual = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 

$background1 = "files/bg.png"; 
$background = imagecreatefrompng($background1); 
//FONTS 
$tahoma = "files/tahoma.ttf"; 
$bebas = "files/BebasNeue.otf"; 
$italic = "files/TahomaItalic.ttf"; 
$bold = "files/TahomaBold.ttf";a 
//COLORS 
$gray = imagecolorallocate($background, 76, 76, 76); 
$dark_shadow = imagecolorallocate($background, 169, 181, 188); 
//NAME 
imagettftext($background, 32, 0, 181, 173, $gray, $bebas, urldecode(between($actual, "name=", "|"))); 
imagepng($background); 
imagedestroy($background); 

的文本是URL參數 「名」。 我需要將此文本居中放置在圖像中。 ?

imagettftext($background, 32, 0, 181, 173, $gray, $bebas, urldecode(between($actual, "name=", "|"))); 

________________________________________ 
|          | 
|          | 
|    MY TEXT    | 
|          | 
|          | 
|          | 
|          | 
|          | 
--------------------------------------- 
+0

你到底在問什麼? – 2014-10-17 12:17:23

+0

@RobertVerkerk我需要在imagepng中使用imagettftext將文本居中。我的意思是我的文本是一個水印,我需要使用php imagepng將它置於圖像中。 – 2014-10-17 12:19:31

回答

0

的URL參數一樣mypage.php名= thename &提交=提交不是名稱之間necesarily =和|我們可以使用$_REQUEST來獲得一個url參數數組。