-->

Generate a stack of Polaroid-like photos from exis

2020-07-30 03:58发布

问题:

I would like to be able to take 5 JPG images and process them with ImageMagick to create an effect showing the photos as a stack of Polaroid-like prints.

Assuming all photos are the same aspect ratio, they need to be resized to the same size, a 10px Polaroid-like border applied, then all slightly rotated and offset such that images below the top one are partially visible around the edges.

The rotation/offset doesn't need to be random as such - it could be hand-coded for each image in the stack if it is easier than doing it truly random?

Here is an example of the effect I am aiming for:

Can someone help with the correct parameters to use - I'm assuming we would want to use convert?

Edit: I already knew about the example contained on the ImageMagick page, but it doesn't specifically address my requirements - they clone the original image, they don't use multiple separate images. They also don't do a great job of explaining in each example exactly what every option does - they assume you already have spent hours (or days!) experimenting with the millions of options available. A bit difficult for someone who has never used the tool to master without a lot of work.

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

... it would be great if someone could expand on this example and show me how to modify it to achieve my desired results as above.

回答1:

Here is the command I found to give a pretty good result for what I needed - thanks to @Jim Lindstrom for putting me on the right track.

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

Here is the output I get from my images using the above command:

It's not perfect yet, I have some more tweaks I'd like to do which I'll ask about in a separate question.



回答2:

The docs for "convert" show almost exactly how. Search for "nice looking pile of photos" on http://www.imagemagick.org/Usage/thumbnails/#polaroid

Here's another way of doing it that makes, hopefully, clearer how one would sub in their own photos:

# 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


回答3:

I use Simpon Hampel Code with some change in this :

How Margin Image with shadow in imagemagick?

please check it..



标签: imagemagick