【问题标题】:How to make tiled image frame without using exec function?如何在不使用 exec 函数的情况下制作平铺图像帧?
【发布时间】: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


【解决方案1】:

在 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.phphttp://us3.php.net/manual/en/imagick.chopimage.phphttp://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

根据需要调整颜色厚度

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多