Scripts problems - IM and Cygwin

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
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 »

I believe its the normal UNIX text editor vi (or its larger public domain equivalent vim)

However wordpad2 and other 'improved' text utilities can set a different line ending.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
markmarques
Posts: 88
Joined: 2010-06-29T14:36:09-07:00
Authentication code: 8675308

Re: Scripts problems - IM and Cygwin

Post by markmarques »

Hi ...
Just to simplify some things :
I edited the script with an ASCII "Unix" friendly editor (I know about LF / CRLF problems in windows... :) ) ...
So when I edited the script I did kept the original EOL terminators...
I suppose the problem is regarding the comparison itself (string versus numeric ) , as someone else pointed above in topic ...

Now the "redist" script does not give any more errors if I tried the escape "\>" or "\<" comparison operators...

But now the resulting image is simply a garbled picture (for instance: the resulting image is possible to distinguish some shapes but the "texture" and color is completly random colored ...

I tried starting with PPM, PNG, JPG as infiles and also with PNG , JPG as output files ...
Call command line :
$redist -s uniform dublin140.jp image.jpg
No sucess ...
I suppose that somewhere in script the comparison changes the heading of the "if branches" ...

Thanks for the fast support ... :)
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 »

post a link to your input image and output image and I can see if it is reproduceable, especially if you have any errors. You can email directly if you want (you have my email address) and add your modified script. I will look it over.

But it seems that you should not have to make those changes, since user el_supremo can run things fine. So the real issue is why you cannot and he can.
markmarques
Posts: 88
Joined: 2010-06-29T14:36:09-07:00
Authentication code: 8675308

Re: Scripts problems - IM and Cygwin

Post by markmarques »

Hi ... again ...
After some more fidling with the "redist script I noticed that the garbled image problem
appears only if I call the script with -s uniform option ...

Although I am using the a modified script where "-ge" were replace by "/>" ...
redist -s uniform sdim011.ppm image.png

with other options (gaussian) everything is ok ...

Thanks in advance
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 »

After some more fidling with the "redist script I noticed that the garbled image problem
appears only if I call the script with -s uniform option ...
That makes no sense to me. Whether you use -s uniform or -s gaussian (default), both use the same conditional tests. Furthermore, the trap for shape is a pure string test and should not need changing. Also if your change to the version trap were to fail, you would be using the older and much slower -fx method rather than -clut. I have not tested the fx code in a long time. In fact the code for -s uniform is much simpler than for gaussian.

So I am very puzzled. As I said before, email me your modified script and let me compare it to mine.

Fred
Tagomago
Posts: 36
Joined: 2011-02-10T09:55:33-07:00
Authentication code: 8675308

Re: Scripts problems - IM and Cygwin

Post by Tagomago »

From reading and re-reading this thread, it seems that no conclusive answer was found on this cygwin problem. I see a previous request to add a screenshot, so since I have the same issue, here it is. Pasted below are failures with Fred's stainedglass, disperse, and frosted scripts.

The final result with each:
Disperse: same image, unchanged
Stained glass: blank image
Frosted: blurry only, not the complete effect.

I'm guessing I've got other errors invovled aside from the problems stated in this thread, so I'm delighted to hear solutions to any of it.

T3500 ~
$ ./stainedglass -k hexagon -b 150 -t 1 test.jpg stained_glass.jpg
./stainedglass: line 295: [: 06060705
06060705: integer expression expected
-1")syntax error: invalid arithmetic operator (error token is "
-1")syntax error: invalid arithmetic operator (error token is "
./stainedglass: line 397: [: 06060705
06060705: integer expression expected
Magick: improper image header `./stainedglass_C_6136.txt' @ error/txt.c/ReadTXTI
mage/431.
Magick: missing an image filename `./stainedglass_1_6136.mpc' @ error/convert.c/
ConvertImageCommand/2949.
Magick: unable to open module file `C:\Program Files\ImageMagick-6.6.7-Q16\modul
es\filters\getColors.dll': No such file or directory @ warning/module.c/GetMagic
kModulePath/683.
Magick: unable to load module `getColors.dll': C:\Program Files\ImageMagick-6.6.
7-Q16\modules\filters\getColors.dll @ error/module.c/InvokeDynamicImageFilter/98
3.
Magick: memory allocation failed SparseColorOption @ error/mogrify.c/SparseColor
Option/458.
Magick: memory allocation failed SparseColorOption @ error/mogrify.c/SparseColor
Option/458.


T3500 ~
$ ./disperse -s 5 -d 5 -c 5 test.jpg disperse.jpg
./disperse: line 123: bc: command not found
./disperse: line 124: [: -eq: unary operator expected
./disperse: line 133: bc: command not found
./disperse: line 134: [: -eq: unary operator expected
./disperse: line 143: bc: command not found
./disperse: line 144: [: -eq: unary operator expected
./disperse: line 227: [: 06060705
06060705: integer expression expected
./disperse: line 234: [: 06060705
06060705: integer expression expected
Mogrify/Image/.[disperse_0_4464.miff]: 1 of 2, 100% complete
Fx/Image/.[disperse_1_4464.mpc]: 595 of 596, 100% complete
save image[disperse.jpg]: 595 of 596, 100% complete

T3500 ~
$ ./frosted -b 3 -s 3 -r 100 test.jpg frosted.jpg
./frosted: line 116: bc: command not found
./frosted: line 117: [: -eq: unary operator expected
./frosted: line 201: [: 06060705
06060705: integer expression expected
./frosted: line 208: [: 06060705
06060705: integer expression expected
Mogrify/Image/.[frosted_0_6980.miff]: 1 of 2, 100% complete
Fx/Image/.[frosted_1_6980.mpc]: 595 of 596, 100% complete
save image[frosted.jpg]: 595 of 596, 100% complete
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 »

In your second and third examples, you are missing the unix bc command in your cygwin. You should be able to find and install that.

In the first case, the test for IM version is failing for some reason that I don't understand in your cygwin as it works fine under Linux/Mac unix.


# test if -process module getcolors exists
if [ "$im_version" -ge "06060210" ]; then
process_test=`convert -list module | grep "getColors"`
fi


You could try changing it to >= and see what happens. This kind of test occurs in a number of places. The strange thing is the version showing in your error does not match what is in my script. Perhaps you need to try to download a more current version of the script.

Unfortunately, I am not a Windows users and probably cannot help too much more than this.
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 »

I recently found the following nifty little routine to test if required utilities (dependencies) are present...

Code: Select all

# Check Dependencies to scripts correct working
DEPENDENCIES="convert sed awk grep tr bc"

for i in $DEPENDENCIES; do
  type $i >/dev/null 2>&1 ||
    Usage "Required program dependency \"$i\" missing"
done
It assumes your internal Usage() subrountine does NOT return but exits.
Other than that, it only uses plain shell built-ins so should work in any environment.

I have added this to IM examples, API, Hints for Better ImageMagick Shell/PHP Scripts
http://www.imagemagick.org/Usage/api/#scripts


ASIDE: while expr is a built-in in BASH, it is not in older bourne shells.
Also note the BASH on MacOSX is much older than BASH in linux and cygwin, as because of this many 'test' and 'expr' functions may not work on MacOSX.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Tagomago
Posts: 36
Joined: 2011-02-10T09:55:33-07:00
Authentication code: 8675308

Re: Scripts problems - IM and Cygwin

Post by Tagomago »

fmw42 - I succesfully installed bc, so that problem is solved.

As for IM, it is the most recent release, and I downloaded the scripts just yesterday off of your site. Is there an updated version I may have missed?

I replaced the two instances of "$im_version" -ge "06060210" with "$im_version" >= "06060210" but the result appears to be the same: (final image had no change)

T3500 ~
$ ./disperse -s 5 -d 5 -c 5 test.jpg disperse.jpg
./disperse: line 227: [: 06060705
06060705: integer expression expected
./disperse: line 234: [: 06060705
06060705: integer expression expected
Mogrify/Image/.[disperse_0_6232.miff]: 1 of 2, 100% complete
Fx/Image/.[disperse_1_6232.mpc]: 595 of 596, 100% complete
save image[disperse.jpg]: 595 of 596, 100% complete

fmw42 & anthony: unfortunately I am woefully ingorant of the basics of coding, scripts, etc. Would it be possible for either of you to provide basic instructions on what else could be changed within the script, and where to change it? Or what other problem I am missing? I really appreciate the help.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Scripts problems - IM and Cygwin

Post by el_supremo »

FWIW: I've just installed the latest cygwin on my WIn 7 Pro 64-bit system. I haven't tried Fred's scripts yet but I made a short script to test one of the errors that had been reported.

Code: Select all

im_version=`convert -list configure | \
sed '/^LIB_VERSION_NUMBER /!d;  s//,/;  s/,/,0/g;  s/,0*\([0-9][0-9]\)/\1/g'`
echo $im_version
if [ "$im_version" -ge "06040805" ]; then echo "ge"; else echo "nge"; fi
which prints:

Code: Select all

06040006
nge
It does not fail with a syntax error.

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 »

Unfortunately I and possibly Anthony use unix and have little knowledge about Windows and cygwin and how cygwin may be different from standard unix. It seems that it does not like the test for IM version because it is testing a number in character format (due to the way IM versions are used, one has to add the leading 0s). I really have no idea how you might change that.

What bothers me is the error message you are showing:

$ ./disperse -s 5 -d 5 -c 5 test.jpg disperse.jpg
./disperse: line 227: [: 06060705
06060705: integer expression expected


In my version of the script that I just download, that line shows a totally different version of IM to be testd:

if [ "$im_version" -ge "06040805" ]; then


There is no reference to 06060705 in that particular script!

So I am totally confounded about what is happening here and where it is getting that number.

It seems that such conditional tests are getting munged in some way.

I would suggest you try some simple tests:

a=1
if [ $a -ge 1 ]; then
echo "True"
else
echo "False"
fi

b="a"
if [ "$b" == "a" ]; then
echo "True"
else
echo "False"
fi

b="a"
if [ "$b" -eq "a" ]; then
echo "True"
else
echo "False"
fi
b="c"
if [ "$b" >= "a" ]; then
echo "True"
else
echo "False"
fi

b="c"
if [ "$b" -ge "a" ]; then
echo "True"
else
echo "False"
fi
a="06"
if [ "$a" -ge "06" ]; then
echo "True"
else
echo "False"
fi


a="06"
if [ "$a" >= "06" ]; then
echo "True"
else
echo "False"
fi
Tagomago
Posts: 36
Joined: 2011-02-10T09:55:33-07:00
Authentication code: 8675308

Re: Scripts problems - IM and Cygwin

Post by Tagomago »

I doublechecked and the script I'm using does say " [ "$im_version" -ge "06040805" ] " and 06060705 appears nowhere. (Of course, that is the IM version I have)

Here are the test results:

a=1
if [ $a -ge 1 ]; then

True

b="a"
if [ "$b" == "a" ]; then

True

b="a"
if [ "$b" -eq "a" ]; then

False [: a: integer expression expected

b="c"
if [ "$b" >= "a" ]; then

False - [: C: unary operator expected

b="c"
if [ "$b" -ge "a" ]; then

False - integer expression expected

a="06"
if [ "$a" -ge "06" ]; then

True

a="06"
if [ "$a" >= "06" ]; then

False - 06: unary operator expected
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 »

a="06"
if [ "$a" -ge "06" ]; then

True


This is the correct behavior for this test. Perhaps it is failing to get your IM version correctly?

try this, then

if [ "06060705" -ge "06040805" ]; then
echo "True"
else
echo "False"
fi

then try

a="06060705"
if [ "$a" -ge "06040805" ]; then
echo "True"
else
echo "False"
fi
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:if [ "$im_version" -ge "06040805" ]; then
There is no reference to 06060705 in that particular script!
That is because that is the contents of the variable $im_version

Code: Select all

 if [ "$im_version" -ge "06040805" ]; then
has the variable substituted

Code: Select all

 if [ "06060705" -ge "06040805" ]; then
whcih is then given to the command '[' Which for some reason did not understand it!

ASIDE: Yes '[' that is a command!!! commands do not need to be alphabetical, just file names. In fact '[' is typically an 'alias' for 'test' so the above really is equivalent to

Code: Select all

if  test  "06060705" -ge "06040805";  then
Typically "test" and "[" commands are built into the shell, but can exist as separate commands on the disk too.

Code: Select all

type [
[ is a shell builtin

BACK to the problem at hand...

Try this and see if that works - perhaps the

Code: Select all

[ "06060705" -ge "06040805" ] && echo "true"
true
That works for me, but if the string contains anything BUT numbers I get...

Code: Select all

[ "x06060705" -ge "06040805" ] && echo "true"
-bash: [: x06060705: integer expression expected
Perhaps the variable is polluted with some non-number junk.
Maybe its just a extra return character or something!

With >= I get

Code: Select all

[ "06060705" >= "06040805" ] && echo "true"
-bash: [: 06060705: unary operator expected
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Tagomago
Posts: 36
Joined: 2011-02-10T09:55:33-07:00
Authentication code: 8675308

Re: Scripts problems - IM and Cygwin

Post by Tagomago »

fmw45: both tests were true

Anthony: I changed that portion of script to:

Code: Select all

if [ "06060705" -ge "06040805" ] && echo "true"; then
# create multi-image miff (sine tmpA1 cosine), then pass to composite -displace
convert $tmp0 \
	-channel R -evaluate sine $density \
	-channel G -evaluate cosine $density \
	-channel RG -separate $tmpA1 +swap miff:- | \
	composite - -displace ${spread}x${spread} $outfile
elif [ "06060705" -ge "06040400" ] && echo "true"; then
# use -fx to create multi-image miff (sine tmpA1 cosine), then pass to composite -displace
(etc.)

and got this result:

$ ./disperse2 -s 5 -d 5 -c 5 test.jpg disperseagain.jpg
true

But... the final image was unchanged.



*also - something interesting I found. In my orginal comment I had tried three of Fred's scripts in cygwin and gotten this problem as a result. But I just found that Huemap for the most part works without any changes.

I wish I could just install unix and be rid of this whole issue, but my overlords want have windows on the server and view even running things with cygwin in that context doubtful. I'm starting to wonder if what I'm tasked to do with Imagemagick is simply not possible in a windows setting. ( Note: that task is to replicate artistic styles of famous artists from actions in photoshop. Those actions primarily use photoshop filters, which mostly don't seem to have an imagemagick equivilent, except in Fred's scripts.)

Speaking of which, is there even anyone who has made windows scripts for Imagemagick? I haven't found any yet.
Post Reply