Learn R Programming

officer (version 0.7.8)

image_dims: Get the dimensions of an image

Description

Get the width and height in pixels of an image file or of a raster object.

The dimensions of 'png', 'jpeg' and 'gif' files are read from their header, without decoding the image, which is much faster. Other formats are read with package 'magick', which must then be installed.

Usage

image_dims(x)

Value

A named numeric vector: width and height, in pixels.

Arguments

x

path to an image file, or a raster object (see grDevices::as.raster()).

Examples

Run this code
img <- file.path(R.home("doc"), "html", "logo.jpg")
image_dims(img)

image_dims(as.raster(matrix(0:1, nrow = 2, ncol = 3)))

Run the code above in your browser using DataLab