Hello,
I have a bit of a problem I am not able to tackle using shell commands on Linux (IM Version 6.8.9-9 016 x86 64).
I have to download several book pages from a server where they are each split into 6 jpgs (3x2 cells per page). I downloaded them, naming each cell per page 1a.jpg, 1b.jpg, ... 1f.jpg, 2a.jpg ... 2f.jpg etc. until 50a.jpg ... 50e.jpg.
Now I want to append these cells to have a single jpeg for each page.
I can do this for one page by using
automatically append jpg files
-
- Posts: 1
- Joined: 2019-07-30T23:19:52-07:00
- Authentication code: 1152
Re: automatically append jpg files
Code: Select all
magick \( 1a.jpg 1b.jpg 1c.jpg +append \) \( 1d.jpg 1e.jpg 1f.jpg +append \) -append 1.jpg
Repeat using bash script. It's not difficult.
Code: Select all
for i in `seq 1 50`
do
magick \( ${i}a.jpg ${i}.jpg ${i}.jpg +append \) \( ${i}d.jpg ${i}e.jpg ${i}f.jpg +append \) -append ${i}.jpg
done
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: automatically append jpg files
If you're using ImagMagick version 7 (... a solution using IM v6 is added below), if your system memory is enough to read all the parts into one command, and if all the images are the same dimensions, something like this should do what you want...lucapearce wrote: ↑2019-07-30T23:23:15-07:00I have to download several book pages from a server where they are each split into 6 jpgs (3x2 cells per page). I downloaded them, naming each cell per page 1a.jpg, 1b.jpg, ... 1f.jpg, 2a.jpg ... 2f.jpg etc. until 50a.jpg ... 50e.jpg.
Now I want to append these cells to have a single jpeg for each page.
Code: Select all
magick *.jpg -set option:wide %[fx:w*3] -set option:high %[fx:h*2] +append +repage \
-crop %[wide]x0 -append +repage -crop 0x%[high] +repage -scene 1 page%03d.jpg
Next it appends all the images into a single horizontal row.
Then it crops that row into pieces 3 times the width of the input images and appends them all vertically.
It finishes by cropping that result into images 2 times the height of the input images, refreshing the paging geometry, and writing the output files.
The outputs will be named "page001.jpg, page002.jpg... page050.jpg", etc., up to the total number of pages in the document.
Edited to add...
You can do almost exactly the same thing using ImageMagick version 6, but you'll have to calculate those width and height variables ahead of the command, something like this...
Code: Select all
wide=`convert 1a.jpg -format %[fx:w*3] info:`
high=`convert 1a.jpg -format %[fx:h*2] info:`
convert *.jpg +append +repage -crop ${wide}x0 -append +repage -crop 0x${high} +repage -scene 1 page%03d.jpg