使用ImageMagick从现有图像生成一堆类似宝丽来的照片

时间:2013-04-19 12:03:11

标签: imagemagick

我希望能够拍摄5张JPG图像并使用ImageMagick处理它们以创建一个效果,将照片显示为一堆类似宝丽来的照片。

假设所有照片都具有相同的宽高比,则需要将它们调整为相同尺寸,应用10px宝丽来边框,然后轻微旋转并偏移,使得顶部下方的图像在边缘部分可见。

旋转/偏移不需要是随机的 - 如果它比真正随机的更容易,可以对堆栈中的每个图像进行手工编码吗?

以下是我的目标效果示例:Stack of Polaroid-like photos

有人可以帮助使用正确的参数 - 我假设我们想要使用convert吗?

编辑:我已经知道ImageMagick页面上包含的示例,但它没有专门解决我的要求 - 他们克隆原始图像,他们不使用多个单独的图像。他们也没有很好地在每个例子中详细解释每个选项的作用 - 他们假设你已经花了几个小时(或几天!)来试验可用的数百万个选项。对于那些从未使用过该工具而没有大量工作的人来说,有点困难。

convert thumbnail.gif \
    -bordercolor white  -border 6 \
    -bordercolor grey60 -border 1 \
    -bordercolor none  -background  none \
    \( -clone 0 -rotate `convert null: -format '%[fx:rand()*30-15]' info:` \) \
    \( -clone 0 -rotate `convert null: -format '%[fx:rand()*30-15]' info:` \) \
    \( -clone 0 -rotate `convert null: -format '%[fx:rand()*30-15]' info:` \) \
    \( -clone 0 -rotate `convert null: -format '%[fx:rand()*30-15]' info:` \) \
    -delete 0  -border 100x80  -gravity center \
    -crop 200x160+0+0  +repage  -flatten  -trim +repage \
    -background black \( +clone -shadow 60x4+4+4 \) +swap \
    -background none  -flatten \
    poloroid_stack.png

...如果有人可以扩展这个例子并告诉我如何修改它以实现我想要的结果,那就太棒了。

3 个答案:

答案 0 :(得分:4)

这是我发现的命令,可以为我所需要的东西提供相当好的结果 - 感谢@Jim Lindstrom让我走上正轨。

convert \
    img-5.jpg -thumbnail 300x200 -bordercolor white -border 10 \
    -bordercolor grey60 -border 1 -bordercolor none \
    -background none -rotate -4 \
    \
    \( img-2.jpg -thumbnail 300x200 -bordercolor white -border 10 \
       -bordercolor grey60 -border 1 -bordercolor none \
       -background none -rotate 6 \
    \) \
    \
    \( img-3.jpg -thumbnail 300x200 -bordercolor white -border 10 \
       -bordercolor grey60 -border 1 -bordercolor none \
       -background none -rotate -2 \
    \) \
    \
    \( img-1.jpg -thumbnail 300x200 -bordercolor white -border 10 \
       -bordercolor grey60 -border 1 -bordercolor none \
       -background none -rotate -4 \
    \) \
    \
    \( img-4.jpg -thumbnail 300x200 -bordercolor white -border 10 \
       -bordercolor grey60 -border 1 -bordercolor none \
       -background none -rotate 4 \
    \) \
    \
    -border 100x80 -gravity center +repage -flatten -trim +repage \
    -background black \( +clone -shadow 60x4+4+4 \) +swap -background none \
    -flatten stack.png

以下是使用上述命令从我的图像中获得的输出:

Polaroid Stack

这还不完美,我还有一些我想做的调整,我会在另一个问题上提出这个问题。

答案 1 :(得分:2)

“转换”的文档几乎完全显示出来。在http://www.imagemagick.org/Usage/thumbnails/#polaroid

上搜索“漂亮的一堆照片”

这是另一种做到这一点的方式,希望能够更清楚地了解自己的照片中的内容:

# create four images we want to use as our polaroid stack (I'm using the same one for all
# one, but you don't have to)
curl -O http://www.imagemagick.org/Usage/thumbnails/thumbnail.gif
cp thumbnail.gif thumbnail1.gif
cp thumbnail.gif thumbnail2.gif
cp thumbnail.gif thumbnail3.gif
cp thumbnail.gif thumbnail4.gif
rm thumbnail.gif

# You can easily see the recurring portion of this command. You could build 
# it up programmatically and then execute it, for however many images you want.
# I've also simplified the example in their docs by hard-coding some rotation
# angles. Feel free to get fancy, or just hard code an array of them and keep
# grabbing the next one.
convert \
   thumbnail1.gif \
   -bordercolor white  -border 6 \
   -bordercolor grey60 -border 1 \
   -bordercolor none  -background  none \
   -rotate 20  \
   -trim +repage \
   \
   \( \
   thumbnail2.gif \
   -bordercolor white  -border 6 \
   -bordercolor grey60 -border 1 \
   -bordercolor none  -background  none \
   -rotate -8 \
   -trim +repage \
   \) \
   -gravity center \
   -composite \
   \
   \( \
   thumbnail3.gif \
   -bordercolor white  -border 6 \
   -bordercolor grey60 -border 1 \
   -bordercolor none  -background  none \
   -rotate 3 \
   -trim +repage \
   \) \
   -gravity center \
   -composite \
   \
   \( \
   thumbnail4.gif \
   -bordercolor white  -border 6 \
   -bordercolor grey60 -border 1 \
   -bordercolor none  -background  none \
   -rotate -17 \
   -trim +repage \
   \) \
   -gravity center \
   -composite \
   \
   -crop 200x160+0+0  +repage  -flatten  -trim +repage \
   -background black \( +clone -shadow 60x4+4+4 \) +swap \
   -background none  -flatten \
   \
   poloroid_stack.png

答案 2 :(得分:0)

我使用Simpon Hampel Code进行了一些改动:

How Margin Image with shadow in imagemagick?

请检查..