How do I place curved text over image in Imagick?

Published

Is there a way to place curved text over an image using Imagick? I have the following code which creates a coloured background as an image and places text over it, then the whole thing is curved but if I were to replace the plain bg with an image, the image is distorted.

How do I keep the image intact but only curve the text?

header("Content-Type: image/png");
        $draw = new ImagickDraw();

        $draw->setFont(public_path("fonts/Roboto-Regular.ttf"));
        $draw->setFontSize(48);
        $draw->setStrokeAntialias(true);
        $draw->setTextAntialias(true);
        $draw->setFillColor('#ff0000');

        $textOnly = new Imagick();
        $textOnly->newImage(600, 300, "rgb(17, 255, 0)");
        $textOnly->setImageFormat('png');
        $textOnly->annotateImage($draw, 30, 40, 0, 'Your Text Here');
        $textOnly->trimImage(0);
        $textOnly->setImagePage($textOnly->getimageWidth(), $textOnly->getimageheight(), 0, 0);

        $distort = array(180);
        $textOnly->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);

        $textOnly->setImageMatte(true);
        $textOnly->distortImage(Imagick::DISTORTION_ARC, $distort, false);

        $textOnly->setformat('png');
        echo $textOnly->getimageblob();

Source: Laravel

Published
Categorised as imagick, laravel, php Tagged , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq