imagemagick - How to create curved text with PHP Imagick? -
how can curved text obtained using imagick (php)? did not expect not find straightforward method or group of methods this, happened...
i did find imagemagick commands obtain curved text (http://www.imagemagick.org/usage/fonts/#arch), i'm in need imagick (pecl extension) -based script.
if want curved, there demo here code below.
$draw = new \imagickdraw(); $draw->setfont("../fonts/arial.ttf"); $draw->setfontsize(48); $draw->setstrokeantialias(true); $draw->settextantialias(true); $draw->setfillcolor('#ff0000'); $textonly = new \imagick(); $textonly->newimage(600, 300, "rgb(230, 230, 230)"); $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'); header("content-type: image/png"); echo $textonly->getimageblob();
if want along path, don't think can in imagick. need create svg file , convert png , overlay on image example of textpath taken https://developer.mozilla.org/en/docs/web/svg/element/textpath
<svg width="100%" height="100%" viewbox="0 0 1000 300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <path id="mypath" d="m 100 200 c 200 100 300 0 400 100 c 500 200 600 300 700 200 c 800 100 900 100 900 100" /> </defs> <use xlink:href="#mypath" fill="none" stroke="red" /> <text font-family="verdana" font-size="42.5"> <textpath xlink:href="#mypath"> go up, go down, again </textpath> </text> <!-- show outline of viewport using 'rect' element --> <rect x="1" y="1" width="998" height="298" fill="none" stroke="black" stroke-width="2" /> </svg>
which needs svg converter supports textpath. 1 built imagemagick not support textpath apparently.
Comments
Post a Comment