Skip to contents

Import images from files and URLs and write images to files, possibly with batch processing.

Usage

image_import(
  img,
  ...,
  which = 1,
  pattern = NULL,
  path = NULL,
  resize = FALSE,
  plot = FALSE,
  nrow = NULL,
  ncol = NULL
)

image_export(img, name, prefix = "", extension = NULL, subfolder = NULL, ...)

image_pliman(img, plot = FALSE)

Arguments

img
  • For image_import(), a character vector of file names or URLs.

  • For image_export(), an Image object, an array or a list of images.

  • For image_pliman(), a charactere value specifying the image example. See ?pliman_images for more details.

...

Alternative arguments passed to the corresponding functions from the jpeg, png, and tiff packages.

which

logical scalar or integer vector to indicate which image are imported if a TIFF files is informed. Defaults to 1 (the first image is returned).

pattern

A pattern of file name used to identify images to be imported. For example, if pattern = "im" all images in the current working directory that the name matches the pattern (e.g., img1.-, image1.-, im2.-) will be imported as a list. Providing any number as pattern (e.g., pattern = "1") will select images that are named as 1.-, 2.-, and so on. An error will be returned if the pattern matches any file that is not supported (e.g., img1.pdf).

path

A character vector of full path names; the default corresponds to the working directory, getwd(). It will overwrite (if given) the path informed in image argument.

resize

Resize the image after importation? Defaults to FALSE. Use a numeric value of range 0-100 (proportion of the size of the original image).

plot

Plots the image after importing? Defaults to FALSE.

nrow, ncol

Passed on to image_combine(). The number of rows and columns to use in the composite image when plot = TRUE.

name

An string specifying the name of the image. It can be either a character with the image name (e.g., "img1") or name and extension (e.g., "img1.jpg"). If none file extension is provided, the image will be saved as a *.jpg file.

prefix

A prefix to include in the image name when exporting a list of images. Defaults to "", i.e., no prefix.

extension

When image is a list, extension can be used to define the extension of exported files. This will overwrite the file extensions given in image.

subfolder

Optional character string indicating a subfolder within the current working directory to save the image(s). If the folder doesn't exist, it will be created.

Value

  • image_import() returns a new Image object.

  • image_export() returns an invisible vector of file names.

  • image_pliman() returns a new Image object with the example image required. If an empty call is used, the path to the tmp_images directory installed with the package is returned.

Author

Tiago Olivoto tiagoolivoto@gmail.com

Examples

library(pliman)
folder <- image_pliman()
full_path <- paste0(folder, "/sev_leaf.jpg")
(path <- file_dir(full_path))
#> [1] "C:/Users/tiago/AppData/Local/R/win-library/4.4/pliman/tmp_images"
(file <- basename(full_path))
#> [1] "sev_leaf.jpg"
image_import(img = full_path)
image_import(img = file, path = path)