如何在不使用 exec 函数的情况下制作平铺图像框?

How to make tiled image frame without using exec function?

原图: 这是我需要的: 它应该从这个小瓷砖创建:

很多人建议使用 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?

另一个很好的解决方案来自 - 但它从大 PNG 帧创建图像,你应该知道正确的图像大小。

我知道我可以用 php GD 创建它 - http://php.net/manual/en/ref.image.php 但我不知道如何以这种方式实现它的正确方法。

在 ImageMagick 中,您可以像这样简单地做一些事情:

convert a1Wit.jpg -mattecolor black -frame 10x10+3+3 -gravity west -chop 3x0 -bordercolor gold -border 3 frame_result.jpg

这些命令应该很容易翻译成 Imagick。参见 http://us3.php.net/manual/en/imagick.frameimage.php and http://us3.php.net/manual/en/imagick.chopimage.php and http://us3.php.net/manual/en/imagick.borderimage.php

或者简单地说:

convert a1Wit.jpg -bordercolor black -border 7 -bordercolor "gray(35%)" -border 3 -bordercolor "#D0A456" -border 3 frame_result2.jpg

或者

convert a1Wit.jpg -mattecolor "gray(30%)" -frame 13x13+5+5 -gravity northwest -shave 5x5 -bordercolor "#D0A456" -border 3 frame_result3.jpg

或者

convert a1Wit.jpg -mattecolor "gray(30%)" -frame 13x13+5+5 -gravity northwest -bordercolor "#D0A456" -border 3 frame_result4.jpg

根据需要调整颜色粗细