【问题标题】:ImageMagick PHP - Distort text and annotate on imageImageMagick PHP - 扭曲文本并在图像上添加注释
【发布时间】:2018-12-11 13:58:57
【问题描述】:

是否可以使用 ImageMagick (PHP) 扭曲文本并在图像上对其进行注释?还是我必须从文本中创建一个图像,扭曲它,然后将其粘贴到我的基础图像上?

我有一个咖啡杯,想添加文字。我想在我的文本中添加一个轻微的弧线,以便在我的杯子上呈现立体外观。

我尝试了拱形字体:

http://www.imagemagick.org/Usage/fonts/#arch

但在我的代码示例中,我无法让它工作,因为文本是 $draw = new ImagickDraw();我不能扭曲它或使用拱形字体。我总是以我的整个图像被扭曲而告终,因为扭曲只适用于像 $image = new Imagick('original/'.$id.'.jpg') 之类的图像

非常感谢任何提示或建议。我需要一个带有一点凹拱的字体,就像这里的例子一样:

http://www.imagemagick.org/discourse-server/viewtopic.php?t=13901

我无法让它在 PHP 中工作。

$fontpath = 'fonts/';
$id = $_REQUEST["id"];
$text1 = $_REQUEST['text1'];
$text2 = $_REQUEST['text2'];

$fontname1 = $_REQUEST['fontname1'];
$fontname2 = $_REQUEST['fontname2'];

$x_coordinate1 = $_REQUEST['x_coordinate1'];
$x_coordinate2 = $_REQUEST['x_coordinate2'];

$y_coordinate1 = $_REQUEST['y_coordinate1'];
$y_coordinate2 = $_REQUEST['y_coordinate2'];

$pointsize1 = $_REQUEST['pointsize1'];
$pointsize2 = $_REQUEST['pointsize2'];

$fill1 = $_REQUEST['fill1'];
$fill2 = $_REQUEST['fill2'];

$stroke1 = $_REQUEST['stroke1'];
$stroke2 = $_REQUEST['stroke2'];

/* Create some objects */
//$image = new Imagick();
$draw = new ImagickDraw();

/* New image */
$image = new Imagick('original/'.$id.'.jpg');

/* Text color */
$draw->setFillColor($fill1);

/* Font properties */
$draw->setFont($fontpath.$fontname1);
$draw->setFontSize( $pointsize1 );

/* Create text */
/* Center is important */
$draw->setGravity (Imagick::GRAVITY_CENTER);
$image->annotateImage($draw, $x_coordinate1, $y_coordinate1, 0, $text1);

/* Text2 color */
$draw->setFillColor($fill2);

/* Font2 properties */
$draw->setFont($fontpath.$fontname2);
$draw->setFontSize( $pointsize2 );

$draw->setGravity (Imagick::GRAVITY_CENTER);


$image->annotateImage($draw, $x_coordinate2, $y_coordinate2, 0, $text2);

/* Give image a format */
$image->setImageFormat('jpg');

/* Output the image with headers */
header('Content-type: image/jpg');
echo $image;

【问题讨论】:

  • 您必须将文本创建为具有透明背景的图像,然后对其进行扭曲。然后将扭曲的文本图像合成到背景图像上。请参阅 imagemagick.org/Usage/fontsimagemagick.org/Usage/distorts/#arc。或者你可以通过 PHP exec() 使用我的 texteffect bash unix shell 脚本。见fmwconcepts.com/imagemagick/index.php
  • 续:请参阅 imagemagick.org/Usage/fonts/#arch 了解拱形和弧形。在透明背景上创建文本图像并按照这些示例对其进行扭曲。将结果合成到您的背景图像上。
  • 好的,谢谢。所以我需要从我的文本中创建另一个图像。我希望我可以避免这种情况。
  • 如果您使用的是 Unix 系统,您可能想在我的网站 fmwconcepts.com/imagemagick/index.php 上探索我的 bash shell 脚本 texteffect。或者查看我上面指定的链接。 Imagemagick 不会在路径上创建文本。因此,您必须创建一个文本图像,然后对其进行扭曲,最后将其合成到您的背景图像上。

标签: php imagemagick imagick


【解决方案1】:

来自 fmw42 的评论最适合我的问题。我将文本创建为具有透明背景的图像,然后扭曲并最终合成到另一个图像上。

【讨论】:

    猜你喜欢
    • 2017-03-14
    • 2012-03-30
    • 1970-01-01
    • 1970-01-01
    • 2020-03-30
    • 1970-01-01
    • 2012-05-31
    • 1970-01-01
    • 2022-01-07
    相关资源
    最近更新 更多