问题
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