I need to create a caption for a picture using two colors, all the words are in black except one in other color…
I’ve been reading the docs of RMagick I can’t find a way of doing this… What I’m using right now to create the text is:
txt_name = Draw.new
image.annotate(txt_name, 0,0,0,0, "This RED has to be in red") do
self.gravity = Magick::NorthGravity
self.pointsize = 20
self.fill = '#000000'
txt_name.font_weight = 100
self.font_family = 'Arial'
end
Any idea?? Or something to read so I can make this work??
Thanks!
Something like the following should work for you. (Please note that this is just to show you the process; I wouldn’t recommend putting code like this into production. This is begging to be put in its own class EDIT: see below):
Set all of the text attributes on the draw object:
Get your image object (this one is just a new blank image):
Set up the strings and measure them with get_type_metrics:
Annotate with the black text:
Change the color to red and add the red text:
Change the color back to black and add the remainder of the text:
Edit: This may give you an idea of how you could structure this a bit nicer:
and a usage example: