Learn R Programming

magick (version 1.2)

painting: Image Painting

Description

The image_fill() function performs flood-fill by painting starting point and all neighboring pixels of approximately the same color. Annotate simply prints some text on the image.

Usage

image_fill(image, color, point = "1x1", fuzz = 0)

image_annotate(image, text, gravity = "northwest", location = "+0+0", degrees = 0, size = 10, font = NULL, color = NULL, strokecolor = NULL, boxcolor = NULL)

Arguments

image

magick image object returned by image_read() or image_graph()

color

a valid color string such as "navyblue" or "#000080"

point

string indicating the flood-fill starting point

fuzz

Colors within this distance are considered equal. Use this option to match colors that are close to the target color in RGB space. I think max distance (from #000000 to #FFFFFF) is 256^2.

text

annotation text

gravity

string with gravity type

location

geometry string with location relative to gravity

degrees

rotates text around center point

size

font-size in pixels

font

rendering font. To use a TrueType font, precede the TrueType filename with an @.

strokecolor

adds a stroke (border around the text)

boxcolor

background color that annotation text is rendered on.

Details

Note that more sophisticated drawing mechanisms are available via the graphics device using image_draw.

See Also

Other image: analysis, animation, attributes, color, composite, device, editing, effects, index, ocr, transform

Examples

Run this code
# NOT RUN {
logo <- image_read("logo:")
logo <- image_transparent(logo, 'white')
image_fill(image_flatten(logo), "red")
image_fill(image_flatten(logo), "red", fuzz = 25600)
# Add some text to an image
image_annotate(logo, "This is a test")
image_annotate(logo, "CONFIDENTIAL", size = 50, color = "red", boxcolor = "pink",
 degrees = 30, location = "+100+100")

# Setting fonts requires fontconfig support (and that you have the font)
myfont <- ifelse(identical("windows", .Platform$OS.type), "courier-new", "courier")
try(image_annotate(logo, "The quick brown fox", font = myfont, size = 50))
# }

Run the code above in your browser using DataLab