Glueing images together

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
UliW
Posts: 19
Joined: 2017-07-19T08:15:59-07:00
Authentication code: 1151

Glueing images together

Post by UliW »

I want to montage two pictures of different size with ImageMagick. My OS is Windows 10, IM is installed in C:\Programme\ImageMagick-7.0.7-Q16; the two pictures (picture1.jpg; picture2.jpg) are in C:\temp\bildablage. Picture1 measures 1.025x1.920 pixels and picture2 is of 1.914 x 1.008 pixels. The result should be in the same folder and named “picture.jpg”.

So I wrote the command-line
C:\Programme\ImageMagick-7.0.7-Q16\magick montage C:\temp\bildablage\picture1.jpg C:\temp\bildablage\picture2.jpg C:\temp\bildablage\picture.jpg

It worked well, so I tried a wildcard for the filenames of the pictures which are be glued together:

C:\Programme\ImageMagick-7.0.7-Q16\magick montage C:\temp\bildablage\*.jpg C:\temp\bildablage\*.jpg C:\temp\bildablage\new.jpg

But the result is a “picture-double-pack”, both pictures are doubled. Does anyone know what happened and how to solve the problem.
https://my.hidrive.com/share/bn5civ45un

Is it possible to put in the file C:\temp\Bildablage with for instance 40 pictures and glue them together each in pairs of two?

Thank you in advance
Uli
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Glueing images together

Post by snibgo »

"*.jpg" means "all the jpg files in that directory". If you have two files, this will be both of them.

If you do that twice, you will get both images, twice.

The obvious solution when you have just two files is to have "*.jpg" only once.

If you have 40 files in the same directory that you want to combine in pairs, I suggest you write a script.
snibgo's IM pages: im.snibgo.com
Devpool
Posts: 5
Joined: 2017-12-07T11:40:56-07:00
Authentication code: 1152

Re: Glueing images together

Post by Devpool »

Assuming 40 pix:

Code: Select all

montage *.jpg -tile 2x20 NewMontage.jpg
You could use a script to count the jpgs and insert the proper number in the -tile flag.

ETA: this python3 script should work for you

Code: Select all

#!/usr/bin/env python3
# coding=utf-8

## call with dir of jpg

import os
import sys
import math
import subprocess
import fnmatch
 
MontageName = "FolderMontage.jpg" # change this to change the montage name
theDir = os.path.abspath(sys.argv[1]) # makes sure we have a full path

os.chdir(theDir) # change to the dir of images
jpgCount = len(fnmatch.filter(os.listdir(theDir), '*.jpg')) # count jpgs
TileFlag = "2x" + str(math.ceil(jpgCount / 2)) # build the number for the -tile flag
subprocess.call(['montage','*.jpg','-tile',TileFlag,MontageName]) # execute montage command
Save as "make_montage.py", make executable, and call it with the directory of images. e.g., make_montage.py path/to/dir

The FolderMontage.jpg will be saved within the directory called.
Post Reply