How to create collage

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
hellocatfood
Posts: 44
Joined: 2010-01-01T13:29:41-07:00
Authentication code: 8675309

How to create collage

Post by hellocatfood »

I have a set of images and want to create a collage similar to this one made in Picasa

Image

I've tried using and modifying this script but it doesn't produce similar results.

What I want the script to do is resize and crop the images to a square then arrange them randomly but in a way that allows me to specify the amount of rows and how many photos are on each row. Repetition of images isn't really a problem at this moment.

Can anyone help?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to create collage

Post by snibgo »

Perhaps this will do what you want. Caution: this is a Windows 7 script.

Code: Select all

set SRC=\pictures\20091205\
del *.png

for %%F in (%SRC%*.jpg) do "%IMG%convert" %%F -gamma .45455 -resize "32x32^^" -crop 32x32+0+0 +repage -gamma 2.2 !RANDOM!_%%~nF.png
  
"%IMG%montage" *.png -geometry 32x32+0+0 -tile 10x10 collage.jpg
Notes:

!RANDOM! will be a random integer each time it is used.

%%~nF will include the original filename (without path or extension) in case two images get the same random number.

If more than 100 input images, we will get multiple outputs.

You can change 32x32 throughout to some other rectangle. Likewise the 10x10 (columns and rows in the output).

Images won't repeat.

%IMG% points to my IM directory. Most people won't need this.
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to create collage

Post by anthony »

hellocatfood wrote:I've tried using and modifying this script but it doesn't produce similar results.
Warning. that script appears to rename images to a random number, but no check is made to prevent two images being saved to the same number!!!!!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
hellocatfood
Posts: 44
Joined: 2010-01-01T13:29:41-07:00
Authentication code: 8675309

Re: How to create collage

Post by hellocatfood »

snibgo wrote:Perhaps this will do what you want. Caution: this is a Windows 7 script.

Code: Select all

set SRC=\pictures\20091205\
del *.png

for %%F in (%SRC%*.jpg) do "%IMG%convert" %%F -gamma .45455 -resize "32x32^^" -crop 32x32+0+0 +repage -gamma 2.2 !RANDOM!_%%~nF.png
  
"%IMG%montage" *.png -geometry 32x32+0+0 -tile 10x10 collage.jpg
Thanks for that!

This code modified for Linux worked for me

Code: Select all

#!/bin/sh
for f in 'ls *.jpg' ; do convert collage_$f -resize "100x100^^" -crop 100x100+0+0 +repage %03d.png; done 

montage *.png -geometry 32x32+0+0 -tile 10x10 collage.jpg
I tried adding an rm command but realised that it could remove the originals too. I tried adding a cp command to rename the files to something different but it didn't work. I might just be doing it wrong
Post Reply