How to draw a long text to a image without wrapping it (using Imagick php)

孤街醉人 提交于 2019-12-13 04:17:40

问题


I want to draw text in a image, using Imagick and PHP (support by Hostgator). I have problem when the text is very long, i don't want to wrapping (new lines), I want to scale width of the text (height is a constant).

Here is a Demo that I want.

Please tell me the solution.

My PHP code:

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;
}

Environment: PHP 7, Imagick extenstion of PHP (support by Hostgator)

Many thanks!

来源:https://stackoverflow.com/questions/54085268/how-to-draw-a-long-text-to-a-image-without-wrapping-it-using-imagick-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!