Page 1 of 1

Glueing images together

Posted: 2018-05-19T11:31:58-07:00
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

Re: Glueing images together

Posted: 2018-05-19T11:48:07-07:00
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.

Re: Glueing images together

Posted: 2018-05-22T11:29:06-07:00
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.