2015-04-25 29 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

如果这对您有用,请将其打勾为正确答案。谢谢 –