我需要使用php中的imagepng & imagettftext函数将图像中的文本居中。
下面是我的代码:
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参数"name“上。我需要将此文本居中显示在图像上。
imagettftext($background, 32, 0, 181, 173, $gray, $bebas, urldecode(between($actual, "name=", "|")));
________________________________________
| |
| |
| MY TEXT |
| |
| |
| |
| |
| |
---------------------------------------发布于 2014-10-18 16:58:04
像mypage.php?name=thename&submit=submit这样的URL参数不一定在name=和|之间
在PHP中,您可以使用$_REQUEST来获取一组URL参数。
https://stackoverflow.com/questions/26424847
复制相似问题