Skip to contents

This function takes an magick-image object as input and applies translations defined by the xy_offset argument. The output image dimensions will remain the same as the input image dimensions, meaning that the transformation might result in cropping the image.

Usage

ImageTranslate(im, xy_offset = NULL)

Arguments

im

An image of class magick-image

xy_offset

A numeric vector of length 2 providing the offsets along the x- and y-axis given as pixels. These values should not exceed the image dimensions.

Value

An object of class magick-image

Author

Ludvig Larsson

Examples


library(magick)
library(semla)
lowresimagefile <- system.file("extdata/mousebrain/spatial",
                               "tissue_lowres_image.jpg",
                               package = "semla")
im <- image_read(lowresimagefile)

# move image 100 pixels to the right and 100 pixels down
im_transformed <- ImageTranslate(im, xy_offset = c(100, 100))
im_transformed
#> # A tibble: 1 × 7
#>   format width height colorspace matte filesize density
#>   <chr>  <int>  <int> <chr>      <lgl>    <int> <chr>  
#> 1 png      565    600 sRGB       TRUE         0 72x72  

# move image 100 pixels to the left and 20 pixels up
im_transformed <- ImageTranslate(im, xy_offset = c(-100, 20))
im_transformed
#> # A tibble: 1 × 7
#>   format width height colorspace matte filesize density
#>   <chr>  <int>  <int> <chr>      <lgl>    <int> <chr>  
#> 1 png      565    600 sRGB       TRUE         0 72x72