我想使用Imagick和PHP(由Hostgator支持)在图像中绘制文本。 当文本很长时,我不想换行(换行),我想缩放文本的宽度(高度是一个常数)。
这是我想要的演示。
请告诉我解决方法。
我的PHP代码:
if(isset($_POST["value1"])){
$image = new Imagick('background.jpg');
$text = $_POST["value1"];
$draw = new ImagickDraw();
$draw->setFont('Arial.ttf');
$draw->setFontSize(25);
$draw->setGravity(Imagick::GRAVITY_SOUTHEAST);
$height = $image->getimageheight();
$width = $image->getimagewidth();
$centerX = $width/2;
$centerY = $height/2;
$draw->setFillColor('#fcf59c');
$image->annotateImage($draw, $centerX, $centerY, 0, "This is a long text");
$image->setImageFormat('png');
header('Content-type: image/png');
echo $image;
}
if(isset($_POST["value1"])){
$image = new Imagick('background.jpg');
$text = $_POST["value1"];
$draw = new ImagickDraw();
$draw->setFont('Arial.ttf');
$draw->setFontSize(25);
$draw->setGravity(Imagick::GRAVITY_SOUTHEAST);
$height = $image->getimageheight();
$width = $image->getimagewidth();
$centerX = $width/2;
$centerY = $height/2;
$draw->setFillColor('#fcf59c');
$image->annotateImage($draw, $centerX, $centerY, 0, "This is a long text");
$image->setImageFormat('png');
header('Content-type: image/png');
echo $image;
}
环境:PHP 7,Imagick对PHP的扩展(由Hostgator支持)
非常感谢!