Page 1 of 1

Porting options to command line imagemagick issues

Posted: 2013-07-05T07:44:45-07:00
by whiskerdoo
I want to replace the color in one image to another, while por. I am doing this using the following command:

Code: Select all

convert image1.png -fill '#ffffff' -opaque '#ff00ff' image2.png
This works fine. However, when I put that script in a quick bash sh file, the contents of which are:

Code: Select all

#!/bin/bash
convert image1.png -fill "'#"$1"'" -opaque '#ff00ff' image2.png
and I run 'sh test.sh ffffff', I get the error "unable to open image `'#ff00ff'' and "no decode delegate for this image format `'#ff00ff''.

Does anyone have any ideas? I've tried checking the literature and the command line works great assuming no options, but i'm not sure if there's something stupid i'm doing.

Re: Porting options to command line imagemagick issues

Posted: 2013-07-05T10:00:29-07:00
by fmw42
too many quotes

try

#!/bin/bash
convert image1.png -fill "#$1" -opaque '#ff00ff' image2.png

Note you must use double quotes to resolve the variable

or

#!/bin/bash
color=$1
convert image1.png -fill "#$color" -opaque '#ff00ff' image2.png

Re: Porting options to command line imagemagick issues

Posted: 2013-07-05T10:34:10-07:00
by whiskerdoo
Thanks for the response. I was able to get it working with the following set of programs:

the php program (which takes a 'GET' color of 6 hex values) (e.g. website.com/colorchange.php?color=ffffff)

Code: Select all

<?php
exec('sh colorchange.sh ' . $_GET["color"]);
?>
and the colorchange.sh command that worked

Code: Select all

convert temp.png -fill "#$1" -opaque '#ffffff' temp1.png
Took me forever figuring out what quote levels worked. Nevertheless, it's working, thank you!