Page 3 of 5

Re: Fred's ImageMagick Scripts

Posted: 2013-05-20T07:16:28-07:00
by creekpeanut
Here is what I get from running the first script.

First run has failed with expr: non-integer argument

Code: Select all

testbox@printdemo ~
$ angle=25

testbox@printdemo ~
$ # compute crop of input into front and side
echo "sign=$sign"
xx=`expr $$ sign + 1`

testbox@printdemo ~
sign=`convert xc: -format "%[fx:$angle<0?0:1]" info:`

testbox@printdemo ~
$ echo "sign=$sign"
sign=1

testbox@printdemo ~
$ xx=`expr $sign + 1`
expr: non-integer argument

testbox@printdemo ~
$ echo $xx

testbox@printdemo ~
$


Second script run fine in shell and in a bash script.

Code: Select all


testbox@printdemo ~
$ angle=25

testbox@printdemo ~
$ # compute crop of input into front and side

testbox@printdemo ~
$ sign=`echo "$angle>0" | bc`

testbox@printdemo ~
$ echo "sign=$sign"
sign=1

testbox@printdemo ~
$ xx=`expr $sign + 1`

testbox@printdemo ~
$ echo $xx
2


Re: Fred's ImageMagick Scripts

Posted: 2013-05-20T10:58:30-07:00
by fmw42
testbox@printdemo ~
$ angle=25

testbox@printdemo ~
$ # compute crop of input into front and side
echo "sign=$sign"
xx=`expr $$ sign + 1`

testbox@printdemo ~
sign=`convert xc: -format "%[fx:$angle<0?0:1]" info:`

testbox@printdemo ~
$ echo "sign=$sign"
sign=1

testbox@printdemo ~
$ xx=`expr $sign + 1`
expr: non-integer argument

testbox@printdemo ~
$ echo $xx

testbox@printdemo ~
$
The part in red, is not what I asked and is not correct syntax. No double $$ and no space

In all these tests, angle must be an integer. If you want to use floats for angle, then you must use bc calculations in place of expr.



try again with

angle=25
# compute crop of input into front and side
sign=`convert xc: -format "%[fx:$angle<0?0:1]" info:`
echo "sign=$sign"
xx=`expr $sign + 1`
echo $xx


If that fails, then try

angle=25
# compute crop of input into front and side
sign=`convert xc: -format "%[fx:round($angle<0?0:1)]" info:`
echo "sign=$sign"
xx=`expr $sign + 1`
echo $xx

or

angle=25
# compute crop of input into front and side
sign=`convert xc: -format "%[fx:$angle<0?0:1]" info:`
sign=`echo $sign "scale=0; $sign/1" | bc`
echo "sign=$sign"
xx=`expr $sign + 1`
echo $xx


Also try

angle=25
# compute crop of input into front and side
sign=`echo "$angle>0" | bc`
echo "sign=$sign"
xx=$((x=1))
echo $xx

Re: Fred's ImageMagick Scripts

Posted: 2013-05-20T12:08:32-07:00
by creekpeanut
try again with

angle=25
# compute crop of input into front and side
sign=`convert xc: -format "%[fx:$angle<0?0:1]" info:`
echo "sign=$sign"
xx=`expr $sign + 1`
echo $xx

Code: Select all

$ ./test
sign=1
expr: non-integer argument

If that fails, then try

angle=25
# compute crop of input into front and side
sign=`convert xc: -format "%[fx:round($angle<0?0:1)]" info:`
echo "sign=$sign"
xx=`expr $sign + 1`
echo $xx

Code: Select all

$ ./test
sign=1
expr: non-integer argument
or

angle=25
# compute crop of input into front and side
sign=`convert xc: -format "%[fx:$angle<0?0:1]" info:`
sign=`echo $sign "scale=0; $sign/1" | bc`
echo "sign=$sign"
xx=`expr $sign + 1`
echo $xx

Code: Select all

$ ./test
(standard_in) 1: illegal character: ^M
(standard_in) 1: parse error
(standard_in) 1: illegal character: ^M
sign=
1
Also try

angle=25
# compute crop of input into front and side
sign=`echo "$angle>0" | bc`
echo "sign=$sign"
xx=$((x=1))
echo $xx

Code: Select all

$ ./test
sign=1
1
I also used ran this and it worked.
angle=25
# compute crop of input into front and side
sign=`echo "$angle>0" | bc`
echo "sign=$sign"
xx=$((sign+1))
echo $xx

Code: Select all

$ ./test
sign=1
2

Re: Fred's ImageMagick Scripts

Posted: 2013-05-20T12:26:12-07:00
by fmw42
angle=25
# compute crop of input into front and side
sign=`echo "$angle>0" | bc`
echo "sign=$sign"
xx=$((x=1))
echo $xx
That was my mistake, it should have been what you tried aftewards.

angle=25
# compute crop of input into front and side
sign=`echo "$angle>0" | bc`
echo "sign=$sign"
xx=$((sign=1))
echo $xx

There seems to be something odd about getting variables from an IM fx calculation. Or perhaps it does not like the back-ticks syntax

Try


angle=25
# compute crop of input into front and side
sign=$(convert xc: -format "%[fx:$angle<0?0:1]" info:)
echo "sign=$sign"
xx=`expr $sign + 1`
echo $xx

or

angle=25
# compute crop of input into front and side
sign=$(convert xc: -format "%[fx:$angle<0?0:1]" info:)
echo "sign=$sign"
xx=$((sign+1))
echo $xx



This is my error


angle=25
# compute crop of input into front and side
sign=`convert xc: -format "%[fx:$angle<0?0:1]" info:`
sign=`echo $sign "scale=0; $sign/1" | bc`
echo "sign=$sign"
xx=`expr $sign + 1`
echo $xx


It should have been the following, so try


angle=25
# compute crop of input into front and side
sign=`convert xc: -format "%[fx:$angle<0?0:1]" info:`
sign=`echo "scale=0; $sign/1" | bc`
echo "sign=$sign"
xx=`expr $sign + 1`
echo $xx

Once I understand what Cygwin is really objecting to I can try to make another version with alternate syntax.

In Cygwin, run

convert -version

and tell me exactly what it says.

Re: Fred's ImageMagick Scripts

Posted: 2013-05-20T13:03:47-07:00
by creekpeanut

Try

angle=25
# compute crop of input into front and side
sign=$(convert xc: -format "%[fx:$angle<0?0:1]" info:)
echo "sign=$sign"
xx=`expr $sign + 1`
echo $xx

Code: Select all

sign=1
expr: non-integer argument
or

angle=25
# compute crop of input into front and side
sign=$(convert xc: -format "%[fx:$angle<0?0:1]" info:)
echo "sign=$sign"
xx=$((sign+1))
echo $xx

Code: Select all

sign=1
")syntax error: invalid arithmetic operator (error token is "

This is my error


angle=25
# compute crop of input into front and side
sign=`convert xc: -format "%[fx:$angle<0?0:1]" info:`
sign=`echo $sign "scale=0; $sign/1" | bc`
echo "sign=$sign"
xx=`expr $sign + 1`
echo $xx


It should have been the following, so try


angle=25
# compute crop of input into front and side
sign=`convert xc: -format "%[fx:$angle<0?0:1]" info:`
sign=`echo "scale=0; $sign/1" | bc`
echo "sign=$sign"
xx=`expr $sign + 1`
echo $xx

Code: Select all

$ ./test
(standard_in) 1: illegal character: ^M
sign=
1

Code: Select all

$ convert -version
Version: ImageMagick 6.8.5-6 2013-05-10 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC OpenMP
Delegates: bzlib fontconfig freetype jng jp2 jpeg lcms lzma pango png ps tiff x xml zlib

Re: Fred's ImageMagick Scripts

Posted: 2013-05-20T13:54:42-07:00
by fmw42
OK.

So please confirm.

This works (and is the only version so far that has worked)

angle=25
# compute crop of input into front and side
sign=`echo "$angle>0" | bc`
echo "sign=$sign"
xx=$((sign+1))
echo $xx


But this does not

angle=25
# compute crop of input into front and side
sign=$(convert xc: -format "%[fx:$angle<0?0:1]" info:)
echo "sign=$sign"
xx=$((sign+1))
echo $xx


Have you tried recompiling IM without OpenMP? Perhaps Cygwin cannot handle the multi-threaded processing.

Re: Fred's ImageMagick Scripts

Posted: 2013-05-20T14:31:15-07:00
by creekpeanut
This is the only one that does work.
angle=25
# compute crop of input into front and side
sign=`echo "$angle>0" | bc`
echo "sign=$sign"
xx=$((sign+1))
echo $xx
I have not tried to recompile the code. I am not to sure how to do this.

Re: Fred's ImageMagick Scripts

Posted: 2013-05-20T16:17:04-07:00
by fmw42
try this

angle=25
# compute crop of input into front and side
sign=$(convert -limit thread 1 xc: -format "%[fx:$angle<0?0:1]" info:)
echo "sign=$sign"
xx=$((sign+1))
echo $xx

or this

angle=25
# compute crop of input into front and side
sign=$(convert -precision 0 xc: -format "%[fx:$angle<0?0:1]" info:)
echo "sign=$sign"
xx=$((sign+1))
echo $xx

Re: Fred's ImageMagick Scripts

Posted: 2013-05-21T07:23:35-07:00
by creekpeanut
It seems it is returning the correct value of 1 but it is not returned as an int but is returned as a 2 character string

angle=25
# compute crop of input into front and side
sign=$(convert -limit thread 1 xc: -format "%[fx:$angle<0?0:1]" info:)
echo "sign=$sign"
xx=$((sign+1))
echo $xx

Code: Select all

$ ./test
sign=1
")syntax error: invalid arithmetic operator (error token is "

angle=25
# compute crop of input into front and side
sign=$(convert -precision 0 xc: -format "%[fx:$angle<0?0:1]" info:)
echo "sign=$sign"
xx=$((sign+1))
echo $xx

Code: Select all

$ ./test
sign=1
")syntax error: invalid arithmetic operator (error token is "

Re: Fred's ImageMagick Scripts

Posted: 2013-05-21T10:39:52-07:00
by fmw42
What version of Windows are you using? I had email from the author of http://www.imagemagick.org/Usage/windows/. He is reporting similar issues with Cygwin and IM under Windows 8, whereas it worked with his earlier Windows OS.

It seems that this is the only way that works properly

angle=25
# compute crop of input into front and side
sign=`echo "$angle>0" | bc`
echo "sign=$sign"
xx=$((sign+1))
echo $xx

whereas this fails for some odd reason


angle=25
# compute crop of input into front and side
sign=$(convert xc: -format "%[fx:$angle<0?0:1]" info:)
echo "sign=$sign"
xx=$((sign+1))
echo $xx

This points to some odd behavior when getting variables from IM commands. I am really not sure how to overcome this except to replace all such commands with bc computations. But that may be hard to do basically because I need to get the image width and height in many scripts.

Test these for me (using the IM built-in image rose: whose width is 70).

width=$(convert rose: -format "%w" info:)
echo "$width;"
xx=$((width-1))
echo "$xx;"

width=$(convert rose: -format "%w" info: 2>&1)
echo "$width;"
xx=$((width-1))
echo "$xx;"

width=$(convert rose: -format "%[fx:w]" info:)
echo "$width;"
xx=$((width-1))
echo "$xx;"

width=$(convert rose: -format "%[fx:w]" info: 2>&1)
echo "$width;"
xx=$((width-1))
echo "$xx;"

Do any of these work?

Re: Fred's ImageMagick Scripts

Posted: 2013-05-21T10:46:27-07:00
by creekpeanut
All of the samples return the following

Code: Select all

$ ./test
70
")syntax error: invalid arithmetic operator (error token is "

My pc is a Windows 7 32bit

Re: Fred's ImageMagick Scripts

Posted: 2013-05-21T10:48:10-07:00
by fmw42
Try again. I made some typos that I was fixing while you were testing.

P.S. Show me your full script as well so that I can be sure it is not malformed.

Re: Fred's ImageMagick Scripts

Posted: 2013-05-21T10:52:45-07:00
by creekpeanut
All of the samples return the following.

Code: Select all

;0
")syntax error: invalid arithmetic operator (error token is "
;

Re: Fred's ImageMagick Scripts

Posted: 2013-05-21T10:56:34-07:00
by fmw42
Show me your script(s) and the full terminal messages from them. I cannot tell where the 0 is coming from

Re: Fred's ImageMagick Scripts

Posted: 2013-05-21T10:59:49-07:00
by creekpeanut