【发布时间】:2017-11-05 02:20:59
【问题描述】:
很多人建议使用 ImageMagick 解决方案(它使用 php exec 函数) - http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=21867:
convert frame_template.gif \
-tile blackthin_top.gif -draw 'color 1,0 floodfill' -rotate 90 \
-tile blackthin_btm.gif -draw 'color 1,0 floodfill' -rotate 90 \
-tile blackthin_top.gif -draw 'color 1,0 floodfill' -rotate 90 \
-tile blackthin_btm.gif -draw 'color 1,0 floodfill' -rotate 90 \
-gravity center thumbnail.gif -composite frame_filled.gif
或
PICFrame 解决方案(它使用 php exec 函数) - http://www.fmwconcepts.com/imagemagick/picframe/index.php:
picframe [-f frameid] [-m mattesize] [-c mattecolor] [-b bordersize] [-s shade] [-a adjust] [-o opacity ] [-d distance] infile outfile
PHP imagick 具有强大的创建颜色边框的能力:
$imagick = new \Imagick('image.jpg');
$imagick->scaleImage(300, 300, false);
// Create frame placeholder
$imagick->frameimage( 'red','30','30', 30, 0);
// Flood fill with color
$imagick->floodFillPaintImage('green', 10, '#6e0000',0, 0,false
);
header("Content-Type: image/jpg");
echo $imagick->getImageBlob();
但是 PHP imagick 不能使用你自己的图像块来创建框架,只能使用纯色。这是一个非常相关的问题 - How to flood fill the frame with a pattern image using imagick php class?
另一个来自 - https://stackoverflow.com/a/28778953/2337706 的好解决方案,但它从大 PNG 帧创建图像,您应该知道正确的图像大小。
我知道我可以使用 php GD - http://php.net/manual/en/ref.image.php 创建它,但我不知道如何以这种方式实现它。
【问题讨论】:
-
使用 PHP exec() 有什么问题?它使使用预先存在的解决方案变得非常容易,而不必重新发明它
-
@fmw42 是的,你是对的,它易于使用和方便,但是很多使用共享主机的客户不提供对 php exec() 的访问,或者我不对?
-
我对 Imagick 做的不多,也没有尝试过,但 us3.php.net/manual/en/imagick.textureimage.php 是平铺图像的功能。您应该能够使用它来实现您想要的结果。
-
我认为您需要询问您的托管服务提供商是否允许 PHP exec()。我在 Godaddy 上用过就好了。
-
您应该能够轻松地将imagemagick.org/Usage/thumbnails/#frame_edge 的平铺框架示例之一转换为 Imagick。
标签: php image-processing imagemagick gd imagick