Page 1 of 1
Split image into two
Posted: 2015-03-30T14:55:50-07:00
by menteith
Hi all,
I am new to IM but I am amazed by its features.
I use the following command to crop and split all jpgs in a folder in two (producing two files)
Code: Select all
convert page000.jpg -crop 2x1@ +repage -colorspace gray +dither -colors 4 *.jpg
from
viewtopic.php?t=19500
but this command tends to not split the last file and makes file names looking quite strange.
I am amazed how IM works and how much time it can save - I have lots of scanned book and the command is to make it less time-consuming
What I would like to achieve is to better naming (e.g. file.jpg -> file_a.jpg file_b.jpg - it is just an example).
What's the best setting to convert scanned books to jpg and then to pdf? The setting I use is great when I print a book it it takes much space.
Thank you!
Re: Split image into two
Posted: 2015-03-30T15:29:07-07:00
by fmw42
Use this syntax for naming:
Code: Select all
convert page000.jpg -crop 2x1@ +repage -colorspace gray +dither -colors 4 page000_%d.jpg
'
The two parts will be named page000_0.jpg and page000_1.jpg
or just
Code: Select all
convert page000.jpg -crop 2x1@ +repage -colorspace gray +dither -colors 4 page000.jpg
'
and the two parts will be named page000-0.jpg and page000-1.jpg
Sorry I do not understand what you mean by
this command tends to not split the last file
Re: Split image into two
Posted: 2015-03-31T02:44:20-07:00
by menteith
Thank you very much for your detailed answer. Please have a look at this output:
D:\split>dir /B
00002.jpg
00037.jpg
00038.jpg
D:\split>convert page000.jpg -crop 2x1@ +repage -colorspace gray +dither -colors 4
page000_%d.jpg *.jpg
D:\split>dir /B
00002.jpg
00037.jpg
00038-0.jpg
00038-1.jpg
00038-2.jpg
00038-3.jpg
00038.jpg
D:\split>
As you can see, I have 3 files:
00002.jpg
00037.jpg
00038.jpg
So, when they are splitted, I should have 3x2=6 files but I have only four:
00038-0.jpg
00038-1.jpg
00038-2.jpg
00038-3.jpg.
The last file have not been splitted.
Is it more clear now?
Re: Split image into two
Posted: 2015-03-31T02:52:38-07:00
by snibgo
Code: Select all
D:\split>convert page000.jpg -crop 2x1@ +repage -colorspace gray +dither -colors 4
page000_%d.jpg *.jpg
Is this a single command (after the DOS prompt)?
What is the "*.jpg" doing at the end?
Without that "*.jpg", the command should read one file called "page000.jpg" and create 2 files called "page000_0.jpg" and "page000_1.jpg".
But your dir command shows no files called "page000.jpg".
Re: Split image into two
Posted: 2015-03-31T02:59:51-07:00
by menteith
Yes, this is one command.
Without that "*.jpg", the command should read one file called "page000.jpg" and create 2 files called "page000_0.jpg" and "page000_1.jpg".
Now everything is clear and works like a charm.
Is there a possibility to rewrite this code this code to work on every jpg in a catalog?
I wanted to achieve this by adding *.jpg at the end of the command.
Re: Split image into two
Posted: 2015-03-31T03:05:42-07:00
by snibgo
I would do it in a FOR loop. Type "help for" for help on "for". I would write the outputs to a different directory. Otherwise, when you process all the jpegs in a directory, you will soon split the split images, and then you will split the splits of the splits ...