Imagemagick设置行间距? [英] Imagemagick set interline spacing?

查看:873
本文介绍了Imagemagick设置行间距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用imagemagick的应用程序中,设计指定如下:

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 \

如何在PHP中访问 interline-spacing 命令行参数?

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

推荐答案

根据这个错误报告,interline-spacing被添加到PHP,但方法 ImagickDraw :: setTextInterlineSpacing 不在我的PHP版本中:

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)

你可以看到它是否在另一个版本。错误报告中还有一个补丁,您可以将其应用于您的PHP版本。否则,您可以使用y坐标和多次调用 Imagick :: annotateImage 编写自己的间距方法。类似于:

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;
   }
}

制作:

这篇关于Imagemagick设置行间距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆