Learn R Programming

statuser (version 0.1.9)

resize_images: Resize Images

Description

Saves images to PNG with a specified width. As input it accepts (SVG, PDF, EPS, JPG, JPEG, TIF, TIFF, BMP, PNG) Saves to subdirectory '/resized' within input folder (or same directory as file if input is a single file)

Usage

resize_images(path, width)

Value

Invisibly returns TRUE on success.

Arguments

path

Character string. Path to a folder containing image files, or path to a single image file.

width

Numeric vector. Target width(s) in pixels for the output PNG files. Can be a single value (recycled for all files) or a vector matching the number of files found.

Details

This function:

  • Searches for image files with extensions: svg, pdf, eps, jpg, jpeg, tif, tiff, bmp, png

  • Creates a "resized" subfolder in the target directory if it doesn't exist

  • Converts each file to PNG format at the specified width(s)

  • Saves output files as: originalname_width.png in the resized subfolder

Supported input formats:

  • Vector graphics: SVG, PDF, EPS (rasterized using rsvg/magick)

  • Raster images: JPG, JPEG, TIF, TIFF, BMP, PNG

Examples

Run this code
# \donttest{
# Create a temporary PNG file and resize it
tmp_png <- tempfile(fileext = ".png")
grDevices::png(tmp_png, width = 400, height = 300)
old_par <- graphics::par(no.readonly = TRUE)
graphics::par(mar = c(2, 2, 1, 1))
graphics::plot(1:2, 1:2, type = "n")
grDevices::dev.off()
graphics::par(old_par)
resize_images(tmp_png, width = 80)
# }

Run the code above in your browser using DataLab