How to draw a long text to a image without wrappin

2019-08-19 13:31发布

问题:

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!

标签: php imagick