如何在imagemagick中自动换行

发布于 2024-09-16 13:59:51 字数 331 浏览 10 评论 0原文

我能够计算出像这样的基本自动换行功能

 $draw = new ImagickDraw();
 $x = 0;
 $y=20;
 $angle = 0;
 $str = "some text for testing of a word wrap in imagemagick";
$str = wordwrap($str, 10,"\r");
$im->annotateImage( $draw, $x, $y, $angle, $str );

,并且似乎工作正常,除了跟踪我认为它称为“你知道行之间的空间太大,以及关于如何解决此问题的想法或想法,或者是否有更好的方法”选项

I was able to figure a basic word wrap function like this

 $draw = new ImagickDraw();
 $x = 0;
 $y=20;
 $angle = 0;
 $str = "some text for testing of a word wrap in imagemagick";
$str = wordwrap($str, 10,"\r");
$im->annotateImage( $draw, $x, $y, $angle, $str );

and that seems to work ok except that the tracking i think its called you know the space between lines is too much and thoughts or ideas on how to fix this or if there is a better option

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

溺深海 2024-09-23 13:59:51

行高由字体规格决定。您当然可以添加一个空行,否则您需要一次渲染一行并手动指定图像中文本的偏移量。

[编辑]:根据OP请求,似乎有一个命令行版本

The line height is determined by the font metric. You could of course add a blank line otherwise you would need to render one line at a time and manually specify the offset of the text within the image.

[EDIT] : On OP request, there appears to be a command-line version of it.

单身狗的梦 2024-09-23 13:59:51

一些重构:

$string = 'Some random Text here';

$y = 120;
$line_height = 50;
$str = wordwrap($string, 20,"\n");
$str_array = explode("\n",$str);
foreach($str_array as $line){
    $image->annotateImage($draw, 0, $y, 0, $line );
    $y += $line_height;
}

Some refactoring:

$string = 'Some random Text here';

$y = 120;
$line_height = 50;
$str = wordwrap($string, 20,"\n");
$str_array = explode("\n",$str);
foreach($str_array as $line){
    $image->annotateImage($draw, 0, $y, 0, $line );
    $y += $line_height;
}
原谅过去的我 2024-09-23 13:59:51

正弦我可以控制渲染每条线的间距

  $draw = new ImagickDraw();
  $x = 0;
  $y=20;
  $angle = 0;
  $padding = 10;
  $str = "some text for testing of a word wrap in imagemagick";
  $str = wordwrap($str, 10,"\r");
  $str_array = explode("\n",$str);
  foreach($str_array as $line)
    $im->annotateImage( $draw, $x, $y+$padding, $angle, $line );
  }

Sine I could control the spacing I went with rendering the lines each

  $draw = new ImagickDraw();
  $x = 0;
  $y=20;
  $angle = 0;
  $padding = 10;
  $str = "some text for testing of a word wrap in imagemagick";
  $str = wordwrap($str, 10,"\r");
  $str_array = explode("\n",$str);
  foreach($str_array as $line)
    $im->annotateImage( $draw, $x, $y+$padding, $angle, $line );
  }
等风来 2024-09-23 13:59:51

您可以让 ImageMagic 为您计算指标详细信息: http://php.net /manual/en/function.imagick-queryfontmetrics.php

You can have ImageMagic calculate the metrics details for you: http://php.net/manual/en/function.imagick-queryfontmetrics.php.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文