I need a script actually.
What if the original pixel was 'white' which is well outside the bounds and as such does not match.
However it does give me a solution, Use one of the colors as BOTH fill and the opaque color.
First convert the users input color to the color name IM would output for the match...
Code: Select all
color2='#e00'
color2=`convert xc:"$color2" -format '%[pixel:s]' info: `
The result was color2="rgb(238,0,0)"
Now do the test
Code: Select all
color1=red
fuzz=1%
result=`convert xc:"$color1" -alpha set -channel RGBA -fuzz $fuzz \
-fill $color2 -opaque $color2 -format '%[pixel:s]' info:`
now if $result = $color2 both strings generated using the same method, then you have a close match.
For fuzz = 1% result = red which does not equal color2 no near match
For fuzz = 10% result = rgb(238,0,0) which matches color2 so match.
I have checked and it works well for ANY color, transparent or otherwise.
The -alpha and -channel options are important for transparent colors,
for example #0002 verses #FFF1 which fuzzy match at about 8% as dose none and #FFF1
Now documented on
Quantization, Color Palette Handling, Comparing Two Colors
http://www.imagemagick.org/Usage/quantize/#compare
Actually Fuzzy matching is still showing mistakes.
It thinks '#0001' is much closer to 'none' than '#FFF1' when really they should be equidistant.
Though I think I know why that is the case.