Search code examples
imagemagick

Copy a pixel color (ImageMagick)


How can I specify a color from an given pixel to -fill ?

convert -gravity center -background rgb\(222,97,56\) -fill "#%[hex:u.p{10,10}/2]" -size 120x60 -pointsize 42 label:Test -depth 8 out.png

Error : convert: unable to open image '#%[hex:u.p{10,10}/2]': No such file or directory

-format '%[hex:p{10,10}/2]\n' info:

returns "6F311C" and -fill "#6F311C" works though.


Solution

  • The following works for me in Imagemagick 7. Add the # sign to your hex command.

    magick -size 120x60 -background "rgb(222,97,56)" -depth 8 -fill "#%[hex:u.p{10,10}/2]" -pointsize 42 -gravity center label:Test -depth 8 out.png
    

    enter image description here

    Note that Imagemagick 7 was implemented to add such in-line computations that were not available in Imagemagick 6.