How can I merge this 8 small images into 1 big image?

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
bemoreim
Posts: 1
Joined: 2019-12-22T23:39:01-07:00
Authentication code: 1152

How can I merge this 8 small images into 1 big image?

Post by bemoreim »

HI, All.

I have splited an image into 8 parts like this command:

$ convert module.jpg -crop 4x2@ out_%02d.png

Then,
How can I merge this 8 small images into 1 big image with same order?

$ convert out_%02d.png -merge 4x2@ out.jpg ??


Thanks in advance ~

Best,
from @bemoregt.

snibgo
Posts: 12657
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can I merge this 8 small images into 1 big image?

Post by snibgo »

Code: Select all

convert x-??.png -background None -layers flatten out.jpg
snibgo's IM pages: im.snibgo.com

246246
Posts: 200
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: How can I merge this 8 small images into 1 big image?

Post by 246246 »

I think what you need is -append and +append, generally.

Code: Select all

magick \( out_00.jpg out_01.jpg out_02.jpg out_03.jpg +append \) \( out_04.jpg  out_05.jpg out_06.jpg out_07.jpg +append \) -append out.jpg

PS

When the intermediate image is png, snibgo's answer works, however if the intermediate image is jpg, i.e.,

Code: Select all

$ magick logo.jpg -crop 4x2@ out_%02d.png
$ magick logo.jpg -crop 4x2@ out_%02d.jpg
it won't work as expected. Because the original offset is not kept in intermediate jpg file.

Code: Select all

$ magick identify out_01.png
out_01.png PNG 160x240 640x480+160+0 8-bit sRGB 31434B 0.000u 0:00.000

$ magick identify out_01.jpg
out_01.jpg JPEG 160x240 160x240+0+0 8-bit sRGB 16650B 0.000u 0:00.000

User avatar
whugemann
Posts: 310
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: How can I merge this 8 small images into 1 big image?

Post by whugemann »

montage.exe resp. magick.exe montage is the suitable tool:

Code: Select all

magick montage out_%02d.jpg -tile 4x2 -geometry x+0+0 module_again.jpg
The option -geometry x+0+0 garantuees seamless montaging.
Wolfgang Hugemann

User avatar
fmw42
Posts: 26055
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How can I merge this 8 small images into 1 big image?

Post by fmw42 »

If you want to reconstruct the original image from the pieces, then use -layer merge with PNG (or MIFF) cropped files. PNG saves the virtual canvas if you do not add +repage after the crop.

# crop

Code: Select all

convert image.png -crop 2x2@ tmp_%02d.png
# reconstitute

Code: Select all

convert tmp_*.png -layers merge result.png

Post Reply