Please help with the batch file

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?".
line7
Posts: 27
Joined: 2018-11-12T07:54:48-07:00
Authentication code: 1152

Please help with the batch file

Post by line7 » 2018-11-12T07:58:41-07:00

We are fast migrating from Xnconvert.

Can you please help us formulate a batch file which will do these two simple actions:

crop image by 10 pixels from all sides
sharpen image by 20%

overwrite all png files in folder:

C:\test

Thanks a lot!!!

PS: I understand this script can be run in a batch command file (bat)?

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

Re: Please help with the batch file

Post by snibgo » 2018-11-12T08:08:43-07:00

What version of IM? Have you read any of the documentation?

What does "sharpen image by 20%" mean?
snibgo's IM pages: im.snibgo.com

line7
Posts: 27
Joined: 2018-11-12T07:54:48-07:00
Authentication code: 1152

Re: Please help with the batch file

Post by line7 » 2018-11-12T08:15:17-07:00

yes I am currently reading the manual - was thinking this was a rather simple operation but being a noin programmer will take some time to formulate properly.....we installed ImageMagick-7.0.8-14-Q16-x64

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

Re: Please help with the batch file

Post by snibgo » 2018-11-12T08:27:45-07:00

Yes, it is simple, for example:

Code: Select all

magick mogrify -shave 10x10 -sharpen 2 *.png
But I don't know what you mean by "sharpen image by 20%".
snibgo's IM pages: im.snibgo.com

line7
Posts: 27
Joined: 2018-11-12T07:54:48-07:00
Authentication code: 1152

Re: Please help with the batch file

Post by line7 » 2018-11-12T08:31:22-07:00

well - there must be a grading of the sharpening? or like sharpen one step?

line7
Posts: 27
Joined: 2018-11-12T07:54:48-07:00
Authentication code: 1152

Re: Please help with the batch file

Post by line7 » 2018-11-12T08:50:01-07:00

can it just sharpen the images once?

line7
Posts: 27
Joined: 2018-11-12T07:54:48-07:00
Authentication code: 1152

Re: Please help with the batch file

Post by line7 » 2018-11-12T08:51:11-07:00

fantastic1
what does this mean? can you please help?

-sharpen 2

line7
Posts: 27
Joined: 2018-11-12T07:54:48-07:00
Authentication code: 1152

Re: Please help with the batch file

Post by line7 » 2018-11-12T08:56:38-07:00

please forgive me for this super dumb question but how do I set the directory for the imagemagick to operate via a BAT file? Can you please show me an example of the full script file in a bat?

line7
Posts: 27
Joined: 2018-11-12T07:54:48-07:00
Authentication code: 1152

Re: Please help with the batch file

Post by line7 » 2018-11-12T13:20:50-07:00

another super dumb question - can I run the whole script inside a BAT file which will contain all instructions? can someone please show me an example of such file if this is possible?

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

Re: Please help with the batch file

Post by fmw42 » 2018-11-12T13:36:12-07:00

Sorry, I am not a Windows user. But about sharpening. -sharpen RadiusxSigma or -sharpen 0x2 for example with sharpen with a Gaussian function whose sigma=2 (standard deviation). The larger the sigma the more sharpening. The radius=0 means for the function to find the optimum radius or window size for the Gaussian function. So I usually leave it at 0. See https://imagemagick.org/script/command- ... hp#sharpen

Another sharpening tool is -unsharp, which is similar to -sharpen, but has more tuning arguments. see https://imagemagick.org/script/command- ... hp#unsharp

For examples, see https://imagemagick.org/Usage/blur/

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

Re: Please help with the batch file

Post by snibgo » 2018-11-12T14:03:18-07:00

line7 wrote:well - there must be a grading of the sharpening? or like sharpen one step?
I suggest you experiment with "-sharpen" or "-unsharp" to find the parameters that give you what you want. If you provide before and after images of "sharpen image by 20%", perhaps we can suggest the settings.

The command I showed can be put in a BAT file. And that's it, a complete script. It will change all the PNG files in the current directory.

To change to a directory, use the Windows "cd" command first.
snibgo's IM pages: im.snibgo.com

line7
Posts: 27
Joined: 2018-11-12T07:54:48-07:00
Authentication code: 1152

Re: Please help with the batch file

Post by line7 » 2018-11-13T02:01:20-07:00

glads to see you here! I made a quantum leap today and was able to create this batch script file which should supposedly work fine but id does not work(((( can someone please take a look?

Code: Select all

cd "C:\test"

mogrify -shave 10x10-sharpen 2 *.*


pause
it seems to run code fine but then nothing is performed on the pictures...they remain the same...

line7
Posts: 27
Joined: 2018-11-12T07:54:48-07:00
Authentication code: 1152

Re: Please help with the batch file

Post by line7 » 2018-11-13T02:05:36-07:00

I changed the code to make the changes more prominent and still it does not operate on the pictures - please help!)

Code: Select all

cd "C:\test"

magick mogrify -colorspace gray -shave 10x10 -sharpen 2 *.jpg


pause

line7
Posts: 27
Joined: 2018-11-12T07:54:48-07:00
Authentication code: 1152

Re: Please help with the batch file

Post by line7 » 2018-11-13T02:09:06-07:00

my antivirus (Comodo) was blocking the bat file - now it seems to work great!)))))!)!)!)!))!)!)!)

line7
Posts: 27
Joined: 2018-11-12T07:54:48-07:00
Authentication code: 1152

Re: Please help with the batch file

Post by line7 » 2018-11-13T02:29:13-07:00

I noticed my CPU is taking like 30% of its power (this is a 16 core xeon E5-2680) to modify 28 images in like 40 seconds (thought this was easy:) - I wonder if shave is resource intensive? can this be done by simple cropping? images are all 1 mb size and 2300X1900 PIXELS WIDE

Post Reply