Porting options to command line imagemagick issues

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
whiskerdoo
Posts: 2
Joined: 2013-07-05T07:28:14-07:00
Authentication code: 6789

Porting options to command line imagemagick issues

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

Re: Porting options to command line imagemagick issues

Post 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
whiskerdoo
Posts: 2
Joined: 2013-07-05T07:28:14-07:00
Authentication code: 6789

Re: Porting options to command line imagemagick issues

Post 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!
Post Reply