IrfanView - image viewer and converter

Submit portable freeware that you find here. It helps if you include information like description, extraction instruction, Unicode support, whether it writes to the registry, and so on.
Message
Author
juverax
Posts: 137
Joined: Mon Jun 11, 2018 5:19 am

IrfanView: CLI/Batch Mode for Scanned Documents

#31 Post by juverax » Sat Aug 29, 2020 11:20 am

[Mod Note: BB tags inserted for easier reading.]

IrfanView - CLI and Batch Mode for Scanned Documents
aka "Stitching Pairs of Graphic Files"

Background information:
When you scan a book with two pages at a time, you can then use ScanTailor to clean, straighten, de-speckle, de-warp and resize all the pages in a batch file.
ScanTailor is a free open source "Postscan Processing Tool" (http://scantailor.org/downloads/)
Scantailor outputs graphic files for each page (left page and right page), and that is the problem that this post solves: reassembling the two pages in one file.

If you want to reassemble the pair of pages in one one file "exactly as the pages were scanned",
you can use IrfanView as a command line tool (CLI) and save the commands in a batch file (DOS script).

I read that you need IrfanView v.4.20 for this special use of the batch mode (I did not verify this assertion).
One place where I found v.4.20 is http://www.oldversion.com/windows/downl ... nview-4-20 (there might be other places)
-- Read Carefully the screens during installation:
-- Do not install the toolbars
-- Archive password: oldversion

Here are the two steps: Resizing the Left/Right pages and stitching the pairs of pages.

Part one: First you have to resize separately the left and right pages, which is easy because ScanTailor assigns specific names for the Left and Right pages, i.e. the file names end in _1L for left pages and _2R for right pages.

-- Here are the command lines:
C:\irfanview420\i_view32.exe C:\inputfiles\*_1L.tif /crop=(0,0,2825,4455) /aspectratio /resample /tifc=4 /convert C:\croptile\*.tif
C:\irfanview420\i_view32.exe C:\inputfiles\*_2R.tifcrop=(95,0,2940,4455) /aspectratio /resample /tifc=4 /convert C:\croptile\*.tif

Note:
= I use tiff B&W files, because this is what works well with ScanTailor.
= An instance of IrfanView420 is residing in folder: C:\irfanview420
= The input files created by ScanTailor are in folder C:\inputfiles
= C:\croptile is the folder where the resized files and the batch file will be stored (this is addressed later in this post)
= The list of parameters (example here: crop=(0,0,2825,4455) must be determined for each book/job, for this step use a suited image viewer/editor, such as MS-Paint

Part two: Reassembling the left and right pages in one file with IrfanView 4.20.

There is an excellent explanation and script at: https://community.ebay.com/t5/Archive-T ... p/16993753

Just in case this gem disappears from the web, I reproduce it here below.
Note that I tried unsuccessfully to save it on the waybackmachine but I got a HTTP 302 and a HTTP 303 error.

>>>>>>>> Partial Copy of the web page BEGINS here
Here is the DOS batch file to stitch two photos together using IrfanView. You will have to modify the file to use it.

Edit the document in a plain text editor like Notepad, then save the file with a suffix of ".bat" which, when clicked, will open a black DOS window.

I call it:

IrfanBatchStitch.bat

Code: Select all

 cls
@ echo.
@ echo.
@ echo.   _________________________________________________________
@ echo.  *                                                         *
@ echo.  *         This batch job will run IrfanView               *
@ echo.  *          to combine two photos into one.                *
@ echo.  *                                                         *
@ echo.  *    It must be placed in the folder containing photos    *
@ echo.  *      and will write composites to the same folder.      *
@ echo.  *                                                         *
@ echo.  *         To Abort, press the Ctrl+C keys.                *
@ echo.  *      or close the window with the top right X           *
@ echo.  *_________________________________________________________*
@ echo.
@ echo.
@ echo.
@ pause
@ echo OFF
:: ------------------------------------
::  DOS Batch file will run IrfanView
::  to composite two photos into one
::  Place this DOS batch within the 
::  folder that contains the photos
:: ------------------------------------
::  Set the full path to the irfanview program
::  Works with irfanview 4.23 but not with 4.36
::  The path for the photos will be the same as this routine, 
::  so the routine will determine it automatically  
:: ------------------------------------
set progpath=C:\Program files\IrfanView\i_view32.exe
set workpath=%CD%\
:: ------------------------------------
:: The orientation will be 1 for horizontal composites and 2 for vertical composites.
:: The three file suffixes will indicate the two source files and the final destination file.
:: The resulting image will be resized to the value given below with a quality of 90, 
:: and there will be no separating gap.
:: Avoid trailing spaces.
:: ------------------------------------
set orientation=1
set suffix1=a.jpg
set suffix2=b.jpg
set suffix3=c.jpg
set imgsize=1600
:: ------------------------------------
:: Destinations files will be overwritten without warning.
:: Images not found will be noted in the error file.
:: ------------------------------------

echo.Working in folder: >imgerrors.txt
echo.    %workpath% >>imgerrors.txt
setlocal EnableDelayedExpansion
for %%i in (*%suffix1%) do (
	set dir=%orientation%
	set orig=%%i
	set mate=!orig:%suffix1%=%suffix2%!
	set final=!orig:%suffix1%=%suffix3%!
	if exist !mate! (
		start /wait "" "%progpath%" "/panorama=(!dir!,%workpath%!orig!,%workpath%!mate!)" /resize_long=%imgsize% /aspectratio /resample /jpgq=90 /convert="%workpath%!final!"
	) else (
		echo.Could not find:  !mate! >>imgerrors.txt
	)
)
endlocal

The first field to edit is the working directory of your IrfanView program. You will find it in the root program files or under a specific user, so change the path to match your own.


set progpath=C:\Program files\IrfanView\i_view32.exe

The next fields to edit are the stitching orientation and the suffixes you are using. suffix1 and suffix2 are the two source images and suffix3 is the destination image. I use a,b,c but you can use front, back, combo or anything else that is meaningful.

set orientation=1
set suffix1=a.jpg
set suffix2=b.jpg
set suffix3=c.jpg
set imgsize=1600

You don't need to edit any other parts of the code.

To run the code, you will need to place the DOS batch program and all your photos into one folder. That means your images can not have the same names as you now have them. It also means they will be stitched together in the same orientation, so make and process a separate folder for horizontal and vertical.

Before stitching your photos, you can preprocess them in IrfanView to batch rename (with the suffixes you will need) and write the new filenames to the new folder where they will later be stitched. Since the merged photos have no separation, you may also want to expand the canvas on two sides with a couple of pixels of white background in the same batch process where you rename your photos. However, if your photos are something like trading cards on a scanner background, then you won't need separation because the scanner background will provide it.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Partial Copy of the web page ENDS here

Now here is my code adapted from the above script:

Code: Select all

set orientation=1
set suffix1=_1L.tif
set suffix2=_2R.tif
set suffix3=.tif

echo.Working in folder: > imgerrors.txt
echo.    %workpath% >> imgerrors.txt
setlocal EnableDelayedExpansion
for %%i in (*%suffix1%) do (
  set dir=%orientation%
  set orig=%%i
  set mate=!orig:%suffix1%=%suffix2%!
  set final=!orig:%suffix1%=%suffix3%!
   if exist !mate! (
     start /wait "" "%progpath%" "/panorama=(!dir!,%workpath%!orig!,%workpath%!mate!)"  /aspectratio /resample /tifc=4 /convert="%workpath%!final!"  
	) else (
		echo.Could not find:  !mate! >>imgerrors.txt
	)
)
endlocal

del *L.*
del *R.*
The script (aka batch file) can be edited with Notepad).

It is stored in a file I named croptile.bat placed in folder c:\croptile (you can name it any name you like). You can place it where you want, but make the corresponding path changes.

Now that we have explained each step, let's put them together in one batch file:

>>>>>>>> Begins Here

Code: Select all

:: Part ONE
C:\irfanview420\i_view32.exe C:\inputfiles\*_1L.tif /crop=(0,0,2825,4455) /aspectratio /resample /tifc=4 /convert C:\croptile\*.tif
C:\irfanview420\i_view32.exe C:\inputfiles\*_2R.tifcrop=(95,0,2940,4455) /aspectratio /resample /tifc=4 /convert C:\croptile\*.tif

:: Part TWO
set orientation=1
set suffix1=_1L.tif
set suffix2=_2R.tif
set suffix3=.tif

echo.Working in folder: > imgerrors.txt
echo.    %workpath% >> imgerrors.txt
setlocal EnableDelayedExpansion
for %%i in (*%suffix1%) do (
  set dir=%orientation%
  set orig=%%i
  set mate=!orig:%suffix1%=%suffix2%!
  set final=!orig:%suffix1%=%suffix3%!
   if exist !mate! (
     start /wait "" "%progpath%" "/panorama=(!dir!,%workpath%!orig!,%workpath%!mate!)"  /aspectratio /resample /tifc=4 /convert="%workpath%!final!"  
	) else (
		echo.Could not find:  !mate! >>imgerrors.txt
	)
)
endlocal

del *L.*
del *R.*
>>>>>>>> Ends HERE

Just double click in Windows on the batch file to run it.

juverax
Posts: 137
Joined: Mon Jun 11, 2018 5:19 am

IrfanView: Working with CLI/BatchFiles

#32 Post by juverax » Sat Aug 29, 2020 3:07 pm

Resources for working with IrfanView from the Command Line (CLI) and Batch Files:

http://www.etcwiki.org/wiki/IrfanView_C ... ne_Options
https://irfanview-forum.de/forumdisplay.php?f=46
https://www.makeuseof.com/tag/10-useful ... ng-images/

Fully working example of a batch script showing how to tile pairs of images with IrfanView.v.4.20
https://community.ebay.com/t5/Archive-T ... p/16993753

Note that some commands do not work with any version of IrfanView.

User avatar
webfork
Posts: 9869
Joined: Wed Apr 11, 2007 8:06 pm
Location: US, Texas
Contact:

Re: IrfanView - image viewer and converter

#33 Post by webfork » Sat Aug 29, 2020 7:33 pm

This sounds amazing -- do you have any before-and-after images to show the process?

juverax
Posts: 137
Joined: Mon Jun 11, 2018 5:19 am

Re: IrfanView - image viewer and converter

#34 Post by juverax » Sun Aug 30, 2020 10:23 am

Webfork:
... do you have any before-and-after images to show the process?
https://xploringtheinternet.blogspot.co ... batch.html

User avatar
webfork
Posts: 9869
Joined: Wed Apr 11, 2007 8:06 pm
Location: US, Texas
Contact:

Re: IrfanView - image viewer and converter

#35 Post by webfork » Sun Aug 30, 2020 3:10 pm

That's *amazing*. Wow.

juverax
Posts: 137
Joined: Mon Jun 11, 2018 5:19 am

Re: IrfanView - image viewer and converter

#36 Post by juverax » Thu Sep 17, 2020 10:40 am

IrfanView: CLI/Batch Mode for Scanned Documents
How to stitch pairs of graphic files using IrfanView batch files from the command line (CLI)

I have archived the URL: https://community.ebay.com/t5/Archive-T ... p/16993753
at: https://archive.is/PGFnU

References (previous posts):
viewtopic.php?f=4&t=16386&start=30#p98084
viewtopic.php?f=4&t=16386&start=30#p98109

rbon
Posts: 295
Joined: Wed Mar 28, 2007 2:16 am
Location: Italy

Re: IrfanView - image viewer and converter

#37 Post by rbon » Thu Feb 25, 2021 11:20 am

Topic update:
IrfanView 4.57 issue:
-> the DLL for the italian language didn't works.
-> the DLL was corrected on 2/25/2021 from 'bovirus' (the italian translator)
• Irfanview Languages page: https://www.irfanview.com/languages.htm
• direct link to new language file: https://www.irfanview.net/lang/irfanvie ... talian.zip

Then please update the '\Languages' folder with containt of new language file, except the file 'Readme.txt'.

IrfanView on Portable Freeware database https://www.portablefreeware.com/index.php?id=49

Post Reply