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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
swiss_knight
Posts: 14
Joined: 2013-05-01T08:12:46-07:00
Authentication code: 6789

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

Post 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. :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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}"
Last edited by fmw42 on 2013-05-01T19:26:58-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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'.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply