I’m currently using Photoshop to resize, rotate randomly, and wrap images randomly to create this type of montage….
I got to thinking that kind of thing should be doable in Imagemagick. I know how to use all of the commands separately, and I can do random rotations and wraps using BASH, but getting a single image out of individual images is eluding me.
Assume that the source pictures are different sizes but should be resized to 250px wide. The images will be named image1.jpg, image2.jpg, etc. Also assume that the destination should be 1000x1000px. Depending on how many pictures I have, the whole 1000×1000 image may not be covered – I understand this. I mainly use BASH, but I have several different environments and shells available to me.
3
Answers
Cool, I'll try fmw42's script, but this is a script I came up with. It generates temporary files (which it deletes) and several convert commands, but it does work....
Here is a bash Imagemagick 6 script that takes a list of images. You can replace it with your images. It uses subshell processing to avoid needing to write temporary images to disk. It saves the images in a miff: format as one file from the loop. Then it pipes the multipage miff: file to -layers merge, which overlays the images onto the 1000×1000 transparent base image. For Imagemagick 7, replace convert with magick.
If you have enough resources to hold all the images at once, then you can also do it in one command line as follows:
Using ImageMagick 6 or 7, if you have enough memory to read in all your images at once you can resize them, randomly rotate them, and place them all in random locations on a 1000×1000 canvas with a command like this…
That uses the ImageMagick built-in image “granite:” duplicated 11 more times. Replace “granite: -duplicate 11” with a list of your input files.
It starts by resizing them all to 250 pixels wide, then placing them each in the center of a 1000×1000 transparent canvas.
The real work is done in the distort operations. First “-distort SRT” rotates each image a random amount between -22.5 and +22.5 degrees. Then the “-distort affine” relocates each image to a random location within the canvas. Any part of an image going beyond the canvas will be rolled back into the opposite side. That makes the result suitable for tiling.
This command flattens everything onto a transparent background wherever it might show between the images. Add “-background blue” just before the “-flatten” operation to change the background to blue, for example.
This works on my IM 6 in bash. For IM 6 in Windows change the continued line backslashes “” to carets “^”. For IM version 7 change “convert” to “magick”.