Split image into two halves using crop command lossless JPG

Discussions on NConvert - the command line tool for image conversion and manipulation

Moderators: XnTriq, xnview

Post Reply
caveatrob
Posts: 1
Joined: Sun Jun 08, 2008 8:59 pm

Split image into two halves using crop command lossless JPG

Post by caveatrob »

Hi all,

I cannot seem to find the proper commands to do the following:

1) Choose a directory full of jpg files
2) Split each file into two parts based on coordinates (the files are scanned book pages with a page on each half of the screen)
3) Save each file into two files, a left and a right half.

I would like to do this in batch. Can someone give me the proper commands to split multiple files in a folder into two separate ones?
User avatar
helmut
Posts: 8219
Joined: Sun Oct 12, 2003 6:47 pm
Location: Frankfurt, Germany

Post by helmut »

First off: Please be very careful with -jpegcrop and -jpegtrans: These manipulations operate directly on the input file and do not generate an output file.. So whenever using these commands make sure you apply them on copies of your original files.

Do your image files have all the same size? If so, you can perform two crops: First crop takes the left side of the image and the second crop the right side.

For a 2048 x 1536 pixel image the batch script looks like this:

Code: Select all

echo off
REM Create output folders
mkdir left_half
mkdir right_half

REM Copy original files (Lossless transformation manipulates input file!)
FOR %%f IN (*.jpg) DO xcopy %%f left_half\
FOR %%f IN (*.jpg) DO xcopy %%f right_half\

REM Crop the left part
cd left_half
FOR %%f IN (*.jpg) DO nconvert -jpegcrop 0 0 1024 1535  %%f

cd ..

REM Crop the right part
cd right_half
FOR %%f IN (*.jpg) DO nconvert -jpegcrop 1024 0 1024 1535 %%f

cd ..
After running this scripts your cropped parts will be in subfolders "left_half" and "right_half".
Post Reply