Batch changing picture files

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
ChristinaChristina
Posts: 7
Joined: 2019-06-16T10:16:33-07:00
Authentication code: 1152

Batch changing picture files

Post by ChristinaChristina » 2019-06-16T11:11:52-07:00

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

snibgo
Posts: 12156
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Batch changing picture files

Post by snibgo » 2019-06-16T11:32:25-07:00

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".
snibgo's IM pages: im.snibgo.com

ChristinaChristina
Posts: 7
Joined: 2019-06-16T10:16:33-07:00
Authentication code: 1152

Re: Batch changing picture files

Post by ChristinaChristina » 2019-06-16T12:21:56-07:00

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.

User avatar
fmw42
Posts: 25560
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Batch changing picture files

Post by fmw42 » 2019-06-16T12:35:56-07:00

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

ChristinaChristina
Posts: 7
Joined: 2019-06-16T10:16:33-07:00
Authentication code: 1152

Re: Batch changing picture files

Post by ChristinaChristina » 2019-06-16T13:41:14-07:00

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?

snibgo
Posts: 12156
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Batch changing picture files

Post by snibgo » 2019-06-16T13:47:23-07:00

Yes.
snibgo's IM pages: im.snibgo.com

ChristinaChristina
Posts: 7
Joined: 2019-06-16T10:16:33-07:00
Authentication code: 1152

Re: Batch changing picture files

Post by ChristinaChristina » 2019-06-16T13:49:40-07:00

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 :)

User avatar
fmw42
Posts: 25560
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Batch changing picture files

Post by fmw42 » 2019-06-16T13:58:32-07:00

Put your file names in double quotes if they have spaces in them

ChristinaChristina
Posts: 7
Joined: 2019-06-16T10:16:33-07:00
Authentication code: 1152

Re: Batch changing picture files

Post by ChristinaChristina » 2019-06-16T14:04:07-07:00

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?

User avatar
fmw42
Posts: 25560
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Batch changing picture files

Post by fmw42 » 2019-06-16T14:14:07-07:00

I am not on Windows, but search Google for Windows .bat scripting for loops

snibgo
Posts: 12156
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Batch changing picture files

Post by snibgo » 2019-06-16T14:18:58-07:00

ChristinaChristina wrote:Can you suggest a good place to read up on how to use shell loops?
Type "help for" at the command line.
snibgo's IM pages: im.snibgo.com

Post Reply