Page 1 of 1

automatically append jpg files

Posted: 2019-07-30T23:23:15-07:00
by lucapearce
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

Re: automatically append jpg files

Posted: 2019-07-31T00:52:45-07:00
by 246246

Code: Select all

magick \( 1a.jpg 1b.jpg 1c.jpg +append \) \( 1d.jpg 1e.jpg 1f.jpg +append \) -append 1.jpg
will do a job for page 1.
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

Re: automatically append jpg files

Posted: 2019-07-31T08:51:15-07:00
by GeeMack
lucapearce wrote:
2019-07-30T23:23:15-07:00
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.
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...

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
That reads in all the images and sets variables to the values of 3 times the width and 2 times the height of a single image.

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