The image_fill()
function performs flood-fill by painting starting point and all
neighboring pixels of approximately the same color. Annotate prints some text on
the image.
image_fill(image, color, point = "+1+1", fuzz = 0, refcolor = NULL)
image_annotate(
image,
text,
gravity = "northwest",
location = "+0+0",
degrees = 0,
size = 10,
font = "",
style = "normal",
weight = 400,
kerning = 0,
decoration = NULL,
color = NULL,
strokecolor = NULL,
strokewidth = NULL,
boxcolor = NULL
)
magick image object returned by image_read()
or image_graph()
a valid color string such as
"navyblue"
or "#000080"
. Use "none"
for transparency.
a geometry_point string indicating the starting point of the flood-fill
relative color distance (value between 0 and 100) to be considered similar in the filling algorithm
if set, fuzz
color distance will be measured against this color,
not the color of the starting point
. Any color (within fuzz
color distance of
the given refcolor
), connected to starting point will be replaced with the color
.
If the pixel at the starting point does not itself match the given refcolor
(according to fuzz
) then no action will be taken.
character vector of length equal to 'image' or length 1
string with gravity value from gravity_types.
geometry string with location relative to gravity
rotates text around center point
font-size in pixels
string with font family such as "sans"
, "mono"
, "serif"
,
"Times"
, "Helvetica"
, "Trebuchet"
, "Georgia"
, "Palatino"
or "Comic Sans"
.
See magick_fonts()
for what is available.
value of style_types for example "italic"
thickness of the font, 400 is normal and 700 is bold, see magick_fonts()
.
increases or decreases whitespace between letters
value of decoration_types for example "underline"
a color string adds a stroke (border around the text)
set the strokewidth of the border around the text
a color string for background color that annotation text is rendered on.
Note that more sophisticated drawing mechanisms are available via the graphics device using image_draw.
Setting a font, weight, style only works if your imagemagick is compiled with fontconfig support.
logo <- image_read("logo:")
logo <- image_background(logo, 'white')
image_fill(logo, "pink", point = "+450+400")
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 sRGB FALSE 0 72x72
image_fill(logo, "pink", point = "+450+400", fuzz = 25)
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 sRGB FALSE 0 72x72
# Add some text to an image
image_annotate(logo, "This is a test")
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 sRGB TRUE 0 72x72
image_annotate(logo, "CONFIDENTIAL", size = 50, color = "red", boxcolor = "pink",
degrees = 30, location = "+100+100")
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 sRGB TRUE 0 72x72
# Setting fonts requires fontconfig support (and that you have the font)
image_annotate(logo, "The quick brown fox", font = "monospace", size = 50)
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 sRGB TRUE 0 72x72