How to draw a long text to a image without wrapping it (using Imagick php)
Posted: 2019-01-11T00:39:10-07:00
Hi everybody,
I want to draw text in a image, using Imagick and PHP7 (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:
Many thanks!
I want to draw text in a image, using Imagick and PHP7 (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:
Code: Select all
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;
}