Page 1 of 1

Batch changing picture files

Posted: 2019-06-16T11:11:52-07:00
by ChristinaChristina
I'm trying to figure out how to make the following changes to all the files in folder c:....\input and save them to c:....\output.
I would really appreciate some help with what I should write as I am a complete newbie at this.
Also, I haven't figured out, should I write this in the command promt in C:\Program Files\ImageMagick-7.0.8-Q16\ or somewhere else?

Sourcefile is grayscale JPG.

* Change mode from grayscale to RGB.
* Add an alpha layer
* Convert all white to transparent
* Change black to red (or even better, if it is possible to get the program for each file to stop and ask me for which color to change to)
* Select a rectangle around the content (i.e. so that transparent area outside is excluded)
* Crop to selection
* Save as png

This is as far as I have gotten so far:
cd /users/me/input/
mogrify -strip -colorspace sRGB -format png -alpha set -fuzz 10% -transparent white ?????? -path /users/me/output/ *.png

Re: Batch changing picture files

Posted: 2019-06-16T11:32:25-07:00
by snibgo
ChristinaChristina wrote:Change black to red
That would be:

Code: Select all

-fill Red -opaque Black
ChristinaChristina wrote:(or even better, if it is possible to get the program for each file to stop and ask me for which color to change to)
IM can't do that. Instead of mogrify, you could have a shell loop to process the files, with the shell asking the user for the colour.
ChristinaChristina wrote:Select a rectangle around the content (i.e. so that transparent area outside is excluded)
Crop to selection
I don't understand. Perhaps "-trim" or "-crop".
ChristinaChristina wrote:Sourcefile is grayscale JPG.
In that case, your mogrify command should end "*.jpg" not "*.png".

Re: Batch changing picture files

Posted: 2019-06-16T12:21:56-07:00
by ChristinaChristina
Many thanks!

With the crop my thought was that I could crop away most of the empty/white area around the text which is written on the sheets that are scanned.

Re: Batch changing picture files

Posted: 2019-06-16T12:35:56-07:00
by fmw42
use -fuzz XX% -trim +repage rather than -crop. See https://imagemagick.org/Usage/crop/#trim If the background color is constant, you can either remove the -fuzz XX% or use XX=0

Re: Batch changing picture files

Posted: 2019-06-16T13:41:14-07:00
by ChristinaChristina
I will try that. Thanks!
Can I add a fuzz to the "-fill Red -opaque Black" in order to capture also the black that might have a hint of grey in it?

Re: Batch changing picture files

Posted: 2019-06-16T13:47:23-07:00
by snibgo
Yes.

Re: Batch changing picture files

Posted: 2019-06-16T13:49:40-07:00
by ChristinaChristina
Just realised that the same fuzz works for all colors so increased it to 30% and now it all works as a charm. Incredible!
Many thanks!
(I didn't work out how to handle the space in the folder names - but moved the files to a folder without space in the name :)

Re: Batch changing picture files

Posted: 2019-06-16T13:58:32-07:00
by fmw42
Put your file names in double quotes if they have spaces in them

Re: Batch changing picture files

Posted: 2019-06-16T14:04:07-07:00
by ChristinaChristina
snibgo wrote: 2019-06-16T11:32:25-07:00
ChristinaChristina wrote:(or even better, if it is possible to get the program for each file to stop and ask me for which color to change to)
IM can't do that. Instead of mogrify, you could have a shell loop to process the files, with the shell asking the user for the colour.
Can you suggest a good place to read up on how to use shell loops?

Re: Batch changing picture files

Posted: 2019-06-16T14:14:07-07:00
by fmw42
I am not on Windows, but search Google for Windows .bat scripting for loops

Re: Batch changing picture files

Posted: 2019-06-16T14:18:58-07:00
by snibgo
ChristinaChristina wrote:Can you suggest a good place to read up on how to use shell loops?
Type "help for" at the command line.