Learn R Programming

magick (version 0.1)

transformations: Image Transformations

Description

Vectorized functions for transforming images. These functions apply the same transformation to each frame in the image. The Magick++ documentation explains meaning of each function and parameter. See editing for functions to read or combine image sequences.

Usage

image_trim(image)
image_background(image, color)
image_crop(image, geometry = "")
image_scale(image, geometry = "")
image_sample(image, geometry = "")
image_border(image, color = "", geometry = "")
image_noise(image, noisetype = "gaussian")
image_blur(image, radius = 1, sigma = 0.5)
image_charcoal(image, radius = 1, sigma = 0.5)
image_edge(image, radius = 1)
image_oilpaint(image, radius = 1)
image_emboss(image, radius = 1, sigma = 0.5)
image_enhance(image)
image_equalize(image)
image_flip(image)
image_flop(image)
image_frame(image, geometry = "25x25+6+6")
image_implode(image, factor = 0.5)
image_negate(image)
image_normalize(image)
image_rotate(image, degrees)
image_fill(image, color, point = "1x1", fuzz = 0)
image_chop(image, geometry)
image_colorize(image, opacity, color)
image_composite(image, composite_image = image[1], operator = "atop", offset = "0x0")
image_contrast(image, sharpen = 1)
image_annotate(image, text, gravity = "northwest", location = "+0+0", degrees = 0, size = 10, font = NULL, color = NULL, strokecolor = NULL, boxcolor = NULL)
image_convert(image, format)

Arguments

image
object returned by image_read
color
a valid color string
geometry
a string with geometry syntax for example "10x10+5-5".
noisetype
integer betwee 0 and 5 with noisetype.
radius
the radius of the Gaussian, in pixels, not counting the center pixel.
sigma
the standard deviation of the Laplacian, in pixels.
factor
image implode factor (special effect)
degrees
how many degrees
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^3.
opacity
percentage of transparency
composite_image
composition image
operator
string with a composite operator.
offset
geometry string with offset
sharpen
enhance intensity differences in image
text
annotation text
gravity
string with gravity type
location
geometry string with location relative to gravity
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.
format
output format such as png, jpeg, gif or pdf.

Details

Each function returns a copy of the manipulated image; the input image will be unaffected. Therefore operations can be piped with magrittr if you're into that kind of stuff.

See Also

Other image: editing

Examples

Run this code
logo <- image_read(system.file("Rlogo.png", package = "magick"))
logo <- image_scale(logo, "400")
image_trim(logo)
image_crop(logo, "400x400+200+200")
image_scale(logo, "200x200")
image_sample(logo, "200x200")
image_border(logo, "red", "10x10")
image_noise(logo)
image_blur(logo, 10, 10)
image_charcoal(logo)
image_edge(logo)
image_oilpaint(logo)
image_emboss(logo)
image_enhance(logo)
image_equalize(logo)
image_flip(logo)
image_flop(logo)
image_frame(logo)
image_implode(logo)
image_negate(logo)
image_normalize(logo)
image_rotate(logo, 45)
image_fill(logo, "red")
image_fill(logo, "red", fuzz = 256^2)
image_chop(logo, "100x20")
image_colorize(logo, 50, "red")
# Compose images using one of many operators
oldlogo <- image_read(system.file("Rlogo-old.png", package = "magick"))
image_composite(logo, oldlogo)
image_composite(logo, oldlogo, operator = "copyred")

# Lights up the R logo
frames <- image_scale(oldlogo, "400x400")
for(i in 1:7) frames <- c(frames, image_contrast(frames[i]))
(blink <- image_animate(c(frames, rev(frames)), fps = 20, loop = 1))

# 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")
image_annotate(logo, "The quick brown fox", font = myfont, size = 50)

Run the code above in your browser using DataLab