【问题标题】:PHP imagettftext center textPHP imagettftext 居中文本
【发布时间】:2014-12-13 00:38:48
【问题描述】:

我需要使用 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 参数“名称”上。 我需要将此文本置于图像的中心。

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

________________________________________
|                                      |
|                                      |
|               MY TEXT                |
|                                      |
|                                      |
|                                      |
|                                      |
|                                      |
---------------------------------------

【问题讨论】:

  • 你到底在问什么?
  • @RobertVerkerk 我需要在 imagepng 中使用 imagettftext 将文本居中。我的意思是示例我的文本是一个水印,我需要使用 php imagepng 将其居中放置在图像中。

标签: php imagettftext


【解决方案1】:

mypage.php?name=thename&submit=submit 这样的URL 参数不一定在name=| 之间

在 PHP 中,您可以使用$_REQUEST 来获取 URL 参数数组。

【讨论】:

    猜你喜欢
    • 2012-04-20
    • 1970-01-01
    • 1970-01-01
    • 2011-01-27
    • 1970-01-01
    • 1970-01-01
    • 2012-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多