ImageMagick PHP - 在图像上扭曲文本和注释

问题描述 投票:2回答:1

是否可以使用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;
php imagemagick imagick
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.