append left and right page images
append left and right page images
I am trying to append a series of left and right opposing page images 001_L.jpg 002_R.jpg and so on. I can create a large batch file like
magick 001_L.jpg 002_R.jpg +append output/page1.jpg
magick 003_L.jpg 004_R.jpg +append output/page2.jpg
......etc
This works and puts the joined images into sub folder 'output' , but as i need to do this for many types of scanned book pages I thought there has to be a simpler method to loop around the all the files using a For loop but i'm not familiar with the use of variables etc and how this would work incrementing the filenames correctly.
Any suggestions
Thanks
magick 001_L.jpg 002_R.jpg +append output/page1.jpg
magick 003_L.jpg 004_R.jpg +append output/page2.jpg
......etc
This works and puts the joined images into sub folder 'output' , but as i need to do this for many types of scanned book pages I thought there has to be a simpler method to loop around the all the files using a For loop but i'm not familiar with the use of variables etc and how this would work incrementing the filenames correctly.
Any suggestions
Thanks
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: append left and right page images
The for loop will be in the script language you use. You haven't said what language that is, eg bash or Windows BAT.
snibgo's IM pages: im.snibgo.com
Re: append left and right page images
hi i'm Running Windows 10, so I guess a .bat file
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: append left and right page images
The messy part is the leading zeros. I add two zeros to the left of the string, and take the final three characters.
To actually run the magick command, remove the "echo" in that line. The other "echo" commands are so you see what is happening, and they can be removed.
If you don't have 6 pairs, change "6" in the first line.
Code: Select all
for /L %%I in (1,1,6) do (
echo %%I
set /A LZL=2*%%I-1
set LZL=00!LZL!
set LZL=!LZL:~-3!
echo !LZL!
set /A LZR=2*%%I
set LZR=00!LZR!
set LZR=!LZR:~-3!
echo !LZL! !LZR!
echo magick !LZL!_L.jpg !LZR!_R.jpg +append output/page%%I.jpg
)
If you don't have 6 pairs, change "6" in the first line.
snibgo's IM pages: im.snibgo.com
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: append left and right page images
If your images are all the same size and if your system has enough memory to read all the images into a single command, something like this should give you the result you're looking for...
Code: Select all
magick *L.jpg -extent %[fx:w*2]x0 null: *R.jpg -gravity east -layers composite output/page%02d.jpg
This assumes, of course, that each page has a mate and that the sequence for reading in the left side images correlates to the sequence for the right side images.
A little tweaking may be required if each image doesn't have a left/right mate.
To work a command like that into a BAT script you'd need to change the single percent signs "%" into doubles "%%".
If the file sizes are especially large, it may tax the memory on your system and a "for" loop would probably be a better approach.
Edited to add: If you want the output file numbers to start with "01" you can add "-scene 1" before the output file name at the end of the command.
Last edited by GeeMack on 2017-11-29T10:09:02-07:00, edited 2 times in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: append left and right page images
As always, a smart solution from GeeMack. It assumes the left and right images in each pair have the same width and height. If that isn't true, it won't be the same as "+append".
snibgo's IM pages: im.snibgo.com
Re: append left and right page images
Hi thanks for the suggestion which I've tried, ( I just put the script in a .bat file and ran the bat file) but couldn't see on screen what was happening (even with the echos in) so I put in a pause in the statement (as you can tell I'm not script writer). However I think it shows where the Left and Right numbering is failing.
C:\Users\stevem\Pictures\test\008_R>(
set /A LZL=2*1-1
set LZL=00!LZL!
set LZL=!LZL:~-3!
echo !LZL!
set /A LZR=2*1
set LZR=00!LZR!
set LZR=!LZR:~-3!
pause
magick !LZL!_L.jpg !LZR!_R.jpg +append output/page1.jpg
)
!LZL!
Press any key to continue . . .
C:\Users\stevem\Pictures\test\008_R>(
set /A LZL=2*1-1
set LZL=00!LZL!
set LZL=!LZL:~-3!
echo !LZL!
set /A LZR=2*1
set LZR=00!LZR!
set LZR=!LZR:~-3!
pause
magick !LZL!_L.jpg !LZR!_R.jpg +append output/page1.jpg
)
!LZL!
Press any key to continue . . .
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: append left and right page images
Add a new line at the top of the BAT file:
Code: Select all
setlocal enabledelayedexpansion
snibgo's IM pages: im.snibgo.com
Re: append left and right page images
GeeMack: a neat solution, as the left and right page sizes are equal. Just ran it and it created nicely paired left and right pages as single images.
Thank you
Thank you
Re: append left and right page images
snibgo: your solution worked nicely as well, and allows for some further editing (coz i can understand what it is happening )