Page 1 of 1

Colorize an image with hex-code

Posted: 2008-09-17T03:40:40-07:00
by derMatze
I need to colorize an image with an hex-code. So I have the original image and an hexcode+alpha like 15243C + 90. That should add #15 to the R-Channel, #24 to the G channel and so on.
I tried this with -channel and -fx but it doesn't work at all, not with #15 or 15 or the decimal 21...
-channel R -fx 'r + 15' -channel G -fx 'g + 36' -channel B -fx 'b + 60'
Any ideas? :(

Similar to that: What does "-channel R -fx 'r+0.1'" mean? More red, ok, but how much, 10%?

Re: Colorize an image with hex-code

Posted: 2008-09-17T10:12:17-07:00
by fmw42
derMatze wrote:I need to colorize an image with an hex-code. So I have the original image and an hexcode+alpha like 15243C + 90. That should add #15 to the R-Channel, #24 to the G channel and so on.
I tried this with -channel and -fx but it doesn't work at all, not with #15 or 15 or the decimal 21...
-channel R -fx 'r + 15' -channel G -fx 'g + 36' -channel B -fx 'b + 60'
Any ideas? :(

Similar to that: What does "-channel R -fx 'r+0.1'" mean? More red, ok, but how much, 10%?

-fx uses normalized channel values in the range from 0 to 1. So r+.1 is r plus 10%

So you will need to convert your hex components to that range to do something like you are trying to do. But if you add a value that goes beyond 1, it will clip to 1.

However, you cannot process the image as a sequence of steps as you have. You will have to create a separate image for each component and then -combine them together.

However, you are making it harder than you need as I believe you can do:

convert -size 100x100 xc:black -fx "u+#FF0000" red100.png

if you need to use alpha as well, you need to enable the alpha channel first by doing the following:

convert -size 100x100 xc:black -channel rgba -matte -fx "u+#FF000000" red100.png

You can replace your input image in place of my -size 100x100 xc:black

Note also there is a -colorize function. seehttp://www.imagemagick.org/script/command-line ... p#colorize where you use percent rather absolute color values

Re: Colorize an image with hex-code

Posted: 2008-09-17T10:18:13-07:00
by derMatze
fmw42 wrote: convert -size 100x100 xc:black -fx "u+#FF0000" red100.png
That's exactly what I needed, so damn easy! :D
Thanks a lot!