run script for batch convert files

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
uni
Posts: 7
Joined: 2017-10-26T06:44:36-07:00
Authentication code: 1151

run script for batch convert files

Post by uni » 2017-10-26T06:54:02-07:00

Hi,
new user here/noob, unfamiliar with image magic, in Cygwin/windows.

my goal is to auto crop some scanned images using the autotrim.sh

how do I provide the source dir for the scanned jpg images and the output dir for the cropped ones?

ex: autotrim.sh -m o -f 30 <input_source_dir_jpg> <output_dir_jpg>

Thanks in advance :o

uni
Posts: 7
Joined: 2017-10-26T06:44:36-07:00
Authentication code: 1151

Re: run script for batch convert files

Post by uni » 2017-10-26T07:03:55-07:00

to be precise i use:

-autotrim.sh -f 30 /cygdrive/c/test/*.jpg /cygdrive/c/test_out/

and i get

line 216:bc command not found
line 217:-eq unary operator expected

convert.exe unable to open image /cygdrive/c/test/t81.jpg
no such file or directory

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

Re: run script for batch convert files

Post by snibgo » 2017-10-26T07:09:44-07:00

uni wrote:line 216:bc command not found
Have you installed bc? If not, that's the problem. Install it from the Cygwin package. I suggest you also install the other common utilities: awk etc. See my web pages on "Cygwin".
snibgo's IM pages: im.snibgo.com

uni
Posts: 7
Joined: 2017-10-26T06:44:36-07:00
Authentication code: 1151

Re: run script for batch convert files

Post by uni » 2017-10-26T07:22:23-07:00

thanks for bc, downloaded and ok

issue with "convert.exe unable to open image /cygdrive/c/test/t81.jpg
no such file or directory" still exists

what is the proper sytnax for input and output?

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

Re: run script for batch convert files

Post by snibgo » 2017-10-26T07:40:58-07:00

Perhaps you don't have that file or directory. What does...

Code: Select all

ls /cygdrive/c/test/t81.jpg
... say?

EDIT: I should add: I think "autotrim" needs a single file for input, without wildcards.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 22109
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: run script for batch convert files

Post by fmw42 » 2017-10-26T09:26:10-07:00

snibgo wrote:EDIT: I should add: I think "autotrim" needs a single file for input, without wildcards.
Correct! One input and one output. So you would have to loop over each image you want to process.

You also have to run the script from a Cygwin terminal window and not from a CMD window.

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

Re: run script for batch convert files

Post by snibgo » 2017-10-26T22:54:08-07:00

It can be run from a CMD window by prefixing the bash command with "bash". Anyhow, the OP's script is running, so that's not the problem. Removing the wildcard may fix it.
snibgo's IM pages: im.snibgo.com

uni
Posts: 7
Joined: 2017-10-26T06:44:36-07:00
Authentication code: 1151

Re: run script for batch convert files

Post by uni » 2017-10-27T01:14:11-07:00

Thank you for helping.
i am running via cygwin terminal

when tried
"mla@mla-PC /cygdrive/c/ImageM/bin
$ ./autotrim.sh -f 30 -C black /cygdrive/c/ebe_theo/8.jpg /cygdrive/c/ebe_theo_out/8t.jpg"


i got

"convert.exe: unable to open image '/cygdrive/c/ebe_theo/8.jpg': No such file or directory @ error/blob.c/OpenBlob/3146.
convert.exe: no images defined `./atrim_A_3164.mpc' @ error/convert.c/ConvertImageCommand/3275.

--- FILE /cygdrive/c/ebe_theo/8.jpg DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO size ---
"

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

Re: run script for batch convert files

Post by snibgo » 2017-10-27T01:36:45-07:00

And what does ls say about that file?
snibgo's IM pages: im.snibgo.com

uni
Posts: 7
Joined: 2017-10-26T06:44:36-07:00
Authentication code: 1151

Re: run script for batch convert files

Post by uni » 2017-10-27T03:01:32-07:00

ls: /cygdrive/c/test/8.jpg

/cygdrive/c/test/8.jpg

also the convert.exe Windows command of IM, works fine with this image file.

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

Re: run script for batch convert files

Post by snibgo » 2017-10-27T03:42:00-07:00

uni wrote:also the convert.exe Windows command of IM, works fine with this image file.
I don't understand. Are you running two different versions of IM, one for CMD and the other for bash? Why?

What happens if you try to convert the file in bash, eg:

Code: Select all

convert /cygdrive/c/test/8.jpg x.png
What command is failing? What happens when you run that command from the console?
snibgo's IM pages: im.snibgo.com

uni
Posts: 7
Joined: 2017-10-26T06:44:36-07:00
Authentication code: 1151

Re: run script for batch convert files

Post by uni » 2017-10-27T04:51:40-07:00

I'm running two different versions because I want to test the syntax and the image file. My goal is to use the script eventually.

The convert command in cygwin doesnt work either.
The error message is the same "unable to open image '/cygdrive/c/ebe_theo/1.jpg' no such file or directory.
So could it be something wrong about the whole package and not just the script? I have downloaded the lastest IM-cygwin.gz file.

In Windows CMD the convert command runs fine with the same image file.

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

Re: run script for batch convert files

Post by snibgo » 2017-10-27T05:08:07-07:00

Nothing wrong with running different versions. I run about ten different versions (different Q numbers, with/without HDRI, v6 or v7, with/without modules). They all work fine under CMD or bash. But I don't understand why you run one under CMD and a different one under bash.
uni wrote:I have downloaded the lastest IM-cygwin.gz file.
What is this? Where did you get it?
Does IM work at all for you under bash? Try basic tests like:

Code: Select all

convert rose: r.png
convert -version
What version is it? What version do you run under CMD?
snibgo's IM pages: im.snibgo.com

uni
Posts: 7
Joined: 2017-10-26T06:44:36-07:00
Authentication code: 1151

Re: run script for batch convert files

Post by uni » 2017-10-27T07:35:32-07:00

i got the package cygwin from here:
https://www.imagemagick.org/script/download.php > https://www.imagemagick.org/download/bi ... win.tar.gz

My cygwin convert -version output is: "7.0.7-8 Q16 x64 2017-10-14"

Isnt really a way to recursively convert the contents of a folder full of .JPG files and recreate the folder structure with the new files?
Do I have to do it one-by-one?

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

Re: run script for batch convert files

Post by snibgo » 2017-10-27T08:24:41-07:00

Ah, I didn't know there was an official IM Cygwin package. It makes sense to have one, for the Cygwin installer to use, but I don't know if it differs from the normal Windows distribution.

Many commands and scripts operate on only one file at a time. You can put it inside a shell "for" loop for all the files in a directory, perhaps including subdirectories. IM won't create directories, so you should do that in your script.
snibgo's IM pages: im.snibgo.com

Post Reply