Scripts problems - IM and Cygwin

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
markmarques
Posts: 88
Joined: 2010-06-29T14:36:09-07:00
Authentication code: 8675308

Scripts problems - IM and Cygwin

Post by markmarques »

Hi ...
I am trying to use Fred WeinHaus scripts but with no sucess...
After some emails t seems that the problem might be my windows Imagemagick / Cygwin configuration.

Using Imagemagick 6.6.2-7 in Windows with Cygwin.

No matter what script I try to run I get several errors like :

/usr/bin/autocolor: line 286: [: 06060207
06060207: integer expression expected

or
/usr/bin/redist: line 572: [: 06060207
06060207: integer expression expected


After some analysis of the scripts I pinpoint the problem after the call

"convert -list configure"


$ convert -list configure
Path: [built-in]

Name Value
-----------------------------------------------------------------------------
NAME ImageMagick
Path: C:\Programas\ImageMagick\config\configure.xml
Name Value
-----------------------------------------------------------------------------
CC vs8
COPYRIGHT Copyright (C) 1999-2010 ImageMagick Studio LLC
DELEGATES bzlib freetype jpeg jp2 lcms png tiff x11 xml wmf zlib
HOST windows-unknown-linux-gnu
LIB_VERSION 0x662
LIB_VERSION_NUMBER 6,6,2,7
NAME ImageMagick
RELEASE_DATE 2010-07-15
VERSION 6.6.2
WEBSITE http://www.imagemagick.org

Path: configure.xml
Name Value
-----------------------------------------------------------------------------
CC vs8
COPYRIGHT Copyright (C) 1999-2010 ImageMagick Studio LLC
DELEGATES bzlib freetype jpeg jp2 lcms png tiff x11 xml wmf zlib
HOST windows-unknown-linux-gnu
LIB_VERSION 0x662
LIB_VERSION_NUMBER 6,6,2,7
NAME ImageMagick
RELEASE_DATE 2010-07-15
VERSION 6.6.2
WEBSITE http://www.imagemagick.org
-------------------------------

Marked in bold is the problem part ...
it seems that "convert -list configure" returns
the strange "LIB_Version_number" as 6,6,2,7
which the script interprets as non-integer number ...

the following line (inside every script) :

im_version=`convert -list configure | sed '/^LIB_VERSION_NUMBER /!d; s//,/; s/,/,0/g; s/,0*\([0-9][0-9]\)/\1/g'`

I get the "strange" value as seen above ...


The scripts do continue but at some point I got the report of a "broken pipe" error ...
Some of the scripts do execute until the end but the resulting image is all messed up
(garbled colors )...

Nonetheless I suppose the problem is with Cygwin configuration ...
Does anyone have some ideas how to configure cygwin or Imagemagick ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Scripts problems - IM and Cygwin

Post by fmw42 »

im_version=`convert -list configure | sed '/^LIB_VERSION_NUMBER /!d; s//,/; s/,/,0/g; s/,0*\([0-9][0-9]\)/\1/g'`
This code is supposed to turn 6,6,2,7 into 06060207 so it can be tested by the if test that is failing. Perhaps your cygwin does not contain the sed module. (Other unix modules that are needed by my scripts include: expr, bc, awk, tr, wc, sort and perhaps other)

You could put an echo in the script after getting im_version above and see what it is returning:

echo "$im_version"

Perhaps it is returning an empty value because it does not have sed and that is causing the if test on the version to fail.
The scripts do continue but at some point I got the report of a "broken pipe" error ...
Which script is this? I will look to see where there is a pipe.

Fred

P.S.

Perhaps one of the windows experts who have been able to run my scripts under Cygwin might provide some pointers about compiling Cygwin and Windows and other things that one needs to do to make my scripts work, I would be grateful and could put those notes on my web site. I already point to http://www.imagemagick.org/Usage/windows/, but perhaps there are others with experience that might offer other details.

Thanks.

Fred
Last edited by fmw42 on 2010-06-30T18:05:36-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Scripts problems - IM and Cygwin

Post by snibgo »

Sorry I can't help. I tried Cygwin and disliked it. Dual boot Windows/Ubuntu was a better solution for me.
snibgo's IM pages: im.snibgo.com
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Scripts problems - IM and Cygwin

Post by el_supremo »

fmw42 wrote:This code is supposed to turn 6,6,2,7 into 06060207 so it can be tested by the if test that is failing
And it must have done that because the error messages contain that string:

Code: Select all

/usr/bin/redist: line 572: [: 06060207
06060207: integer expression expected
Therefore "sed" is working. I ran the redist script under cygwin on Win XP Pro SP3 and it works without complaint.
I don't know what is wrong but line 572 in the redist script does not reference the im_version string.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
markmarques
Posts: 88
Joined: 2010-06-29T14:36:09-07:00
Authentication code: 8675308

Re: Scripts problems - IM and Cygwin

Post by markmarques »

After some fidling with the code I get to this :

in the scripts (autocolor , redist , etc , etc ) the following
if [ "$im_version" -ge "06030507" ]
I replaced it by
if [ "$im_version" \> "06030507" ]

(I know it is different by missing the equal part )
but at least works as it was supposed to ...

Nonetheless , it seems that the shell (cygwin) considers those 2 vars as "strings" not as numbers ... ?!
So, the -ge (greater than or equal ) does messes up the shell comparation operator...

Although the scripts are now working I do have strange results with the redist script ...
At first I thought that could be some problem of because PNG 16bits per channel PNG file ...
But now I tried the redist script (no running errors ) from a 8bit channel JPG into another 8bit channel JPG
and the resulting file was a garble colour file.... :(

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

Re: Scripts problems - IM and Cygwin

Post by fmw42 »

markmarques wrote:After some fidling with the code I get to this :

in the scripts (autocolor , redist , etc , etc ) the following
if [ "$im_version" -ge "06030507" ]
I replaced it by
if [ "$im_version" \> "06030507" ]

(I know it is different by missing the equal part )
but at least works as it was supposed to ...

Nonetheless , it seems that the shell (cygwin) considers those 2 vars as "strings" not as numbers ... ?!
So, the -ge (greater than or equal ) does messes up the shell comparation operator...

Although the scripts are now working I do have strange results with the redist script ...
At first I thought that could be some problem of because PNG 16bits per channel PNG file ...
But now I tried the redist script (no running errors ) from a 8bit channel JPG into another 8bit channel JPG
and the resulting file was a garble colour file.... :(

Any ideas ?

It is a string compare. I got that from Anthony. See http://www.imagemagick.org/Usage/api/#scripts

Perhaps it does not like the double quotes around the version number that I put in as the limiting version? Or perhaps your sed is not working or perhaps Cygwin is still confused by that string compare.

Anyone else having that problem with this comparison test on Cygwin?

Send me your input an output image that does not work right with redist (and any errors) and I will check.
Last edited by fmw42 on 2010-06-30T18:06:51-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Scripts problems - IM and Cygwin

Post by fmw42 »

el_supremo wrote:Therefore "sed" is working. I ran the redist script under cygwin on Win XP Pro SP3 and it works without complaint.
I don't know what is wrong but line 572 in the redist script does not reference the im_version string.
That is true. Line 572 is some other test in redist. Perhaps he has an older version of redist. The latest mod is dated 7/16/2009. Perhaps other errors accumulated until it got to that point. I don't know?

What have you done, el_supremo, with installing Cygwin and IM and any auxiliary unix things like sed, bc, etc such that it does not complain for you and the scripts run?

What were your install steps and any other important things to consider about notation and directories?

Fred
Last edited by fmw42 on 2010-06-30T18:07:19-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Scripts problems - IM and Cygwin

Post by fmw42 »

On my Mac OSX Tiger:


im_version="06030600"

# works
[ "$im_version" -lt '06030600' ] && echo "1" || echo "2"
2


# not work
[ "$im_version" < '06030600' ] && echo "1" || echo "2"
-bash: 06030600: No such file or directory
2


# works
[ "$im_version" \< '06030600' ] && echo "1" || echo "2"
2


# not work
[ $im_version < 06030600 ] && echo "1" || echo "2"
-bash: 06030600: No such file or directory
2


# works
[ $im_version \< 06030600 ] && echo "1" || echo "2"
2

# works
[ $im_version -lt 06030600 ] && echo "1" || echo "2"
2
Last edited by fmw42 on 2010-06-30T18:49:43-07:00, edited 2 times in total.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Scripts problems - IM and Cygwin

Post by el_supremo »

One thing that can cause trouble with the script is if it has been edited in windows and saved with the Windows end of line which uses both CR and LF, whereas Linux is only LF.

Code: Select all

# Test part of Fred's redist script
im_version=`convert -list configure | \
	sed '/^LIB_VERSION_NUMBER /!d;  s//,/;  s/,/,0/g;  s/,0*\([0-9][0-9]\)/\1/g'`
if [ "$im_version" -ge "06030507" ]
	then 
	echo "GE"
else
	echo "LT"
fi
echo $im_version
The above script works when saved with Linux EOL but fails when Windows EOL is used.

Re: Bash comparison operators
see: http://tldp.org/LDP/abs/html/comparison-ops.html

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Scripts problems - IM and Cygwin

Post by fmw42 »

Exactly. It is a string ASCII alphabetic order comparison. It explains why one needs to escape the > or <, which I had not known before.

Thanks.
One thing that can cause trouble with the script is if it has been edited in windows and saved with the Windows end of line which uses both CR and LF, whereas Linux is only LF.
Good point about the end of line markers. That may just be the issue. Somehow they may have been converted on download and save to Windows (even before he tried to edit them).

Fred
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Scripts problems - IM and Cygwin

Post by anthony »

fmw42 wrote: It is a string compare. I got that from Anthony. See http://www.imagemagick.org/Usage/api/#scripts
The number is a fixed length of 8 characters. You should be able to compare it as numbers (using -ge) or as strings. The result should be the same -- that is test if the current IM version is larger than the number your testing against.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Scripts problems - IM and Cygwin

Post by anthony »

However it looks as if a check on test -ge compatibility under cgiwin is not going to happen.

The end of line fault could be the reason for the failure, but we may never know for certain any more.

The test however should work, and should be universally compatible.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Scripts problems - IM and Cygwin

Post by anthony »

An alternative test that should also be usable is to use "expr" instead of "test" (or its "[" command equivalent)

Code: Select all

 if  expr + "$im_version" \>= "06030507" >/dev/null;
then ....
fi
The "expr" will only test the IM version as numbers, not strings.

WARNING; the extra '+' in the above is normally not needed, at least for this test, but is needed if the variable could contain the special keyword "match" which would give "expr" problems.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Scripts problems - IM and Cygwin

Post by fmw42 »

Very useful information.

But, I think perhaps we are getting a little off topic here. The issue is how to help markmarques figure out why my scripts are failing on his Cygwin/Windows and not how to change the failing test. If el_supremo can get my scripts and this kind of test to work, the issue is what is he doing differently or how is his compile different.

Best guess here so far is that of line endings in downloading and saving the file from unix to windows without losing the unix line endings that are needed by Cygwin.
Last edited by fmw42 on 2010-06-30T21:03:35-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Scripts problems - IM and Cygwin

Post by snibgo »

... downloading and saving the file from unix to windows without losing the unix line endings that are needed by Cygwin.
In Windows 7, downloading Fred's redist script with Firefox 3.5.10, the file retains the Unix line endings. (Firefox doesn't muck around changing characters.)

Some Windows text editors (such as Microsoft Wordpad) will replace with cr-lf endings, which is bad news. I assume Cygwin includes an editor that doesn't.
snibgo's IM pages: im.snibgo.com
Post Reply