2

我希望在 imagick 图像中垂直显示文本。

例如,我有“测试”文本,但我想要这样的文本:

时间
_
_
_

你有什么主意吗?谢谢。

4

1 回答 1

1

哎呀!我看到你要求一个 PHP 解决方案。我不会删除它,而是留下它,因为它可能对将来可能正在寻找命令行版本的其他人有用。

由于似乎没有人想为您做一个 PHP 版本,这里有一种方法应该可以工作 - 现在只是伪代码:

create empty output image with transparent background
for each letter in the string do
   create a new transparent image larger than necessary
   use annotateImage() to draw single letter on transparent image
   use trimImage() to get rid of superfluous space around image
   repage image with setImagePage(0, 0, 0, 0) 
   add a small transparent border around the image so letters don't touch - use borderImage()
   append this image to vertical stack with appendImages(true)
done

你可以做这样的事情,虽然它是相当丑陋的!

printf "Vertical" | perl -pe 's/(.)/\1\n/g' |
   convert -background cyan -fill magenta -pointsize 36 -gravity center label:@- result.gif

在此处输入图像描述

我只是用它自己替换每个字符,然后在该Perl部分中添加一个换行符,然后将其传递到从中读取它的convert命令中。label:@-stdin

于 2017-10-03T12:25:44.747 回答