Imagemagick set interline spacing?

…衆ロ難τιáo~ 提交于 2019-12-13 16:56:21

问题


In application using imagemagick the design is specified like this:

   $draw->setFillColor(new ImagickPixel("#FFFFFF"));
   $draw->setstrokecolor(new ImagickPixel("#000000"));
   $draw->setstrokewidth(1);
   $draw->setFontSize(18);
   $draw->setfontweight(100);
   $draw->setFont("fonts/Impact.ttf");

I'd like to set interline Spacing in a similair fashion, but all samples are displayed like this:

  convert -density 72 -pointsize 12 -interline-spacing 12  -font Arial \

How can I access the interline-spacing command line parameter in PHP?


回答1:


According to this bug report, interline-spacing was added to PHP, but the method ImagickDraw::setTextInterlineSpacing isn't in my version of PHP:

# php -v
PHP 5.3.3-7+squeeze14 with Suhosin-Patch (cli) (built: Aug  6 2012 20:08:59)

You could see if it's in another version. There's also a patch in the bug report that you could apply to your version of PHP. Otherwise, you could write your own spacing method using the y-coordinate and multiple calls to Imagick::annotateImage. Something like:

<?php

$image = new Imagick();
$image->newImage(250, 300, "none");
$draw = new ImagickDraw();
$draw->setFillColor("black");
$draw->setFontSize(18);
$text = "Image Magick\nwowowow\nit's magical";
annotate_spaced($image, $draw, 0, 40, 0, $text, 40);
$image->setImageFormat("png");
header("Content-type: image/png");
echo $image;

function annotate_spaced($image, $draw, $x, $y, $ang, $text, $spacing)
{
   $lines = explode("\n", $text);
   foreach ($lines as $line)
   {
      $image->annotateImage($draw, $x, $y, $ang, $line);
      $y += $spacing;
   }
}

Makes:



来源:https://stackoverflow.com/questions/14198215/imagemagick-set-interline-spacing

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