Page 1 of 1

[Linux/bash] giving -sparse-color arguments as a string ?!

Posted: 2013-05-01T08:20:39-07:00
by swiss_knight
Hello,
I'm using bash on Linux to do some stuff on my pictures and I've got a small issue with convert and the -sparse-color option. :(

When calling -sparse-color like this, it works like a charm :

Code: Select all

$ convert -size 900x900 xc: -sparse-color  Shepards \
          '150,150 rgb(0,255,255) 150,450 rgb(1,5,5) 150,750 rgb(252,1,251) 450,150 rgb(238,255,254)'  \
          sparse_color.jpg
But if I put all the values needed by the -sparse-color option in a string, like that :

Code: Select all

$ string="'150,150 rgb(0,255,255) 150,450 rgb(1,5,5) 150,750 rgb(252,1,251) 450,150 rgb(238,255,254)'"
$ echo ${string}
 '150,150 rgb(0,255,255) 150,450 rgb(1,5,5) 150,750 rgb(252,1,251) 450,150 rgb(238,255,254)' 
It doesn't work anymore :

Code: Select all

$ convert -size 900x900 xc: -sparse-color  Shepards \
          "${string}"  \
          sparse_color.jpg
 
convert: invalid argument for option `sparse-color': Invalid number of Arguments @ error/mogrify.c/SparseColorOption/443. 
And I really need to put all the arguments chain in a single string because they are depending on some other variables and their number may vary.

Any help or advices would be really appreciated !
Thanks a lot. :)

Re: [Linux/bash] giving -sparse-color arguments as a string

Posted: 2013-05-01T09:25:54-07:00
by fmw42
try without the double quotes

convert -size 900x900 xc: -sparse-color Shepards \
${string} \
sparse_color.jpg

If that does not work, then try removing the single quotes from

$ string="'150,150 rgb(0,255,255) 150,450 rgb(1,5,5) 150,750 rgb(252,1,251) 450,150 rgb(238,255,254)'"

and then try either ${string} or "${string}"

Re: [Linux/bash] giving -sparse-color arguments as a string

Posted: 2013-05-01T18:57:37-07:00
by anthony
You have quotes in the string, which are then being passed to IM.
IM is faling to parse the unexpected quotes.

Sparse color requires a very specialised parse to convert the given string to a list of floating point numbers (and is more complex for the color to numbers). This is highly specialised and is soly to make sparse colors easier to use.

This parse could probably use some more work, especially to make it more accessible for use by other non-CLI API's, like MagickWand, PerlMagick, and PHP Imagick.

However I don't have time for that, as any time I do have is devoted to IMv7 scripting. Specifically global use of percent escapes in all option arguments, and then the addition of script argument handling. When that is done I have mogrify, montage, and compare to merge into the IMv7 scripting system, as well as 'example and documentation writing'.