Page 2 of 5

Re: Fred's ImageMagick Scripts

Posted: 2013-05-14T14:52:33-07:00
by creekpeanut
Looks like bc was not instaled.

Getting a little more down the code.

Here is the current error.

Code: Select all

$ sh /cygdrive/c/cygwin/home/testbox/3Dcover wedding.jpg show:
convert.exe: unable to open image `/tmp/3Dcover_1_2940.mpc': No such file or dir                                                                                                    ectory @ error/blob.c/OpenBlob/2644.

--- FILE wedding.jpg DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR                                                                                                     HAS ZERO size ---
This is where it stops in the code.

Code: Select all

# read the input image into the temporary cached image and test if valid
convert -quiet -regard-warnings "$infile" +repage "$tmpA1" ||
	errMsg "--- FILE $infile DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO size  ---"

Re: Fred's ImageMagick Scripts

Posted: 2013-05-14T15:23:31-07:00
by fmw42
Did you provide the full path to your image? It won't find it unless it is in the directory where you are launching the script, that is, you current directory.

Also I am not sure if show: will work properly. So for now try specifying an actual output file.

Did you change the default temp directory to dir="/tmp"?

Re: Fred's ImageMagick Scripts

Posted: 2013-05-16T08:30:20-07:00
by creekpeanut
Ok I am stumped.

Looks like I have the error trapped. Just a little stumped and what the issue is.

Code: Select all

echo "1"
# get image dimensions
ww=`convert $tmpA1 -format "%w" info:`
echo "2"
hh=`convert $tmpA1 -format "%h" info:`
echo "3"
hm1=$((hh-1))
echo "4"
I added the echo statements to the code like you suggest and once I run the code this is what I get.

Code: Select all

$ sh /cygdrive/c/cygwin/home/testbox/3Dcover a.jpg b.jpg
1
2
3
")syntax error: invalid arithmetic operator (error token is "

Just for kicks I downloaded your other script 2colorthresh just to make sure I could run one of you scripts. I had no issue with running this.

I am sure it is something simple. Thanks again for the help.

Re: Fred's ImageMagick Scripts

Posted: 2013-05-16T08:58:04-07:00
by glennrp
Shouldn't it be ($(hh)-1) not $((hh-1)) ?

Re: Fred's ImageMagick Scripts

Posted: 2013-05-16T09:31:14-07:00
by creekpeanut
Thanks guys I am a little closer now.

Code: Select all

$ sh /cygdrive/c/cygwin/home/testbox/3Dcover a.jpg b.jpg
1
2
: integer expression expectedtbox/3Dcover: line 511: [: 1
4
5
")syntax error: invalid arithmetic operator (error token is "

Code: Select all

echo "1"
# compute crop of input into front and side
sign=`convert xc: -format "%[fx:$angle<0?0:1]" info:`
echo "2"
if [ $sign -eq 1 ]; then
echo "3"
	#crop side on left and rotate about join line
	rangle=$angle
	langle=$((angle-90))
	wl=$side
	wr=$((ww-wl+1))
	lcrop="${wl}x${hh}+0+0"
	rcrop="${wr}x${hh}+${wl}+0"
	shadsign="-"
else
echo "4"
	#crop side on right and rotate about join line
	langle=$angle
	rangle=($((90+angle)))
	wr=$side
echo "5"	
	wl=$((ww-wr+1)) 
echo "6"	
	lcrop="${wl}x${hh}+0+0"
	rcrop="${wr}x${hh}+${wl}+0"
	shadsign="+"
fi
seems there is an issue with the if statement and also the trap error between echo 5 and echo 6.

Re: Fred's ImageMagick Scripts

Posted: 2013-05-16T11:18:26-07:00
by fmw42
glennrp wrote:Shouldn't it be ($(hh)-1) not $((hh-1)) ?
$((hh-1)) works fine on my system

Re: Fred's ImageMagick Scripts

Posted: 2013-05-16T11:19:49-07:00
by fmw42
rangle=($((90+angle)))
That is not what I have in my script.

If you follow Glennrp's suggestion then it would be ($(90+angle))

According to http://tldp.org/LDP/abs/html/dblparens.html

it could be

(( rangle = 90+angle ))

Re: Fred's ImageMagick Scripts

Posted: 2013-05-16T11:25:07-07:00
by fmw42
$((hh-1)) works fine on my system


see for example
http://bash.cyberciti.biz/guide/Perform ... operations


Perhaps his unix does not like that (Posix) syntax. So one would have to revert those calculations to the older

hm1=`expr $hh - 1`
or
hm1=$(expr $hh - 1)


or see the following for other possible syntax uses
http://stackoverflow.com/questions/2517 ... xpressions
http://mywiki.wooledge.org/ArithmeticExpression
http://www.bashguru.com/2010/12/math-in ... ripts.html

Alternately replace all those calculations with IM -fx calculations, such as

hm1=`convert xc: -format "%[fx:$hh-1]" info:`

Re: Fred's ImageMagick Scripts

Posted: 2013-05-16T12:39:30-07:00
by creekpeanut
Seems my issue just could my cygwin setup.

I think I am just missing some packages to be installed.

I did figure out one of the issues is with this line of code
sign=`convert xc: -format "%[fx:$angle<0?0:1]" info:`
it is suppose to return return an integer of 1 in this current context.

the value is not coming out as an integer but as a string with a length of two characters

So when the condition "if [ $sign -eq 1 ]; then" runs it fails with the error message.

integer expression expected.

Think you could tell me what packages I should have installed?

Re: Fred's ImageMagick Scripts

Posted: 2013-05-16T12:45:20-07:00
by fmw42
sign=`convert xc: -format "%[fx:$angle<0?0:1]" info:`
This is a simple IM calculation that is assigned to the variable sign. It should have worked fine if your cygwin accepts calculations assigned to a variable.

From your terminal window try

angle=30
echo $angle

30
convert xc: -format "%[fx:$angle<0?0:1]" info:
1


angle=-30
echo $angle

-30
convert xc: -format "%[fx:$angle<0?0:1]" info:
0

What do you get returned in place of the 30, -30, 1 and 0?


Likewise try

x=10
xx=$((x-1))
echo $xx

9

or

x=10
xx=`expr $x - 1`
echo $xx

9

or


x=10
let xx=x-1
echo $xx

9

Re: Fred's ImageMagick Scripts

Posted: 2013-05-17T14:27:15-07:00
by creekpeanut
So I think I know what the issue is but can not seem to figure out how to resolve it.

Take for example this small code from 3Dcover.

Code: Select all

#!/bin/bash

angle=25
# compute crop of input into front and side
sign=`convert xc: -format "%[fx:$angle<0?0:1]" info:`
echo "sign value:" $sign
echo "Length of sign:" ${#sign}
xx=$((sign + 1))
echo $xx
and the out put.

Code: Select all

./test
sign value: 1
Length of sign: 2
")syntax error: invalid arithmetic operator (error token is "
The value of $sign=1. But the length of $sign=2.
What would cause $sign to have 2 characters?

Re: Fred's ImageMagick Scripts

Posted: 2013-05-17T14:35:58-07:00
by fmw42
#!/bin/bash

angle=25
# compute crop of input into front and side
sign=`convert xc: -format "%[fx:$angle<0?0:1]" info:`
echo "sign value:" $sign
echo "Length of sign:" ${#sign}
xx=$((sign + 1))
echo $xx
This is not in my code. ${#sign} I am not even sure what that does. I am not familiar with that syntax except when used with arrays.

It has no relevance. I never ask for the length.

The question is what do you get from

#!/bin/bash

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

If that does not work then

#!/bin/bash

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

You never answered my question above about what you got from all the tests I asked you to run!

If you go off on a tangent, it is not helping me to uncover where the issue might be with what your version of Cygwin unix can run in the way of math calculations.

Re: Fred's ImageMagick Scripts

Posted: 2013-05-17T14:39:08-07:00
by creekpeanut
Sorry about that.

Running all of the statements you had above worked great with no issue.

The echo "Length of sign:" ${#sign} is something I did to see the length of the returned value from "sign=`convert xc: -format "%[fx:$angle<0?0:1]" info:`"

It seemed kinda strange that it says the length was 2 and not 1.

this is what I get when running either of the small code sample above.

Code: Select all

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

Re: Fred's ImageMagick Scripts

Posted: 2013-05-17T15:49:55-07:00
by fmw42
creekpeanut wrote:Sorry about that.

Running all of the statements you had above worked great with no issue.

this is what I get when running either of the small code sample above.

Code: Select all

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

I am puzzled. All the code I asked you to run earlier worked fine. Correct? So you got 1 for 30 degree and 0 for -30 degrees?


But the last code gave this error? But where did the error come in terms of the echo statements. Can you show me the whole thing from your terminal when you ran the above code, so I can see where it is objecting?

Re: Fred's ImageMagick Scripts

Posted: 2013-05-17T15:51:22-07:00
by fmw42
fmw42 wrote:
creekpeanut wrote:Sorry about that.

Running all of the statements you had above worked great with no issue.

this is what I get when running either of the small code sample above.

Code: Select all

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

I am puzzled. All the code I asked you to run earlier worked fine. Correct? So you got 1 for 30 degree and 0 for -30 degrees?


But the last code gave this error? But where did the error come in terms of the echo statements. Can you show me the whole thing from your terminal when you run the code below, so I can see where it is objecting? Just copy and paste this code into your terminal (do not put it into a shell script)

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=`echo "$angle>0" | bc`
echo "sign=$sign"
xx=`expr $sign + 1`
echo $xx

If these both work, then put them into a bash shell script and try them that way. Perhaps your Cygwin unix is not properly installed or does not have bash?