Skip to content

Instantly share code, notes, and snippets.

@ivelasq
Created July 30, 2024 17:14
Show Gist options
  • Save ivelasq/7b45ac741d168e8bde906e0162096065 to your computer and use it in GitHub Desktop.
Save ivelasq/7b45ac741d168e8bde906e0162096065 to your computer and use it in GitHub Desktop.
Resizing images using R
library(magick)
input_folder <- "test/"
output_folder <- "resized/"
if (!dir.exists(output_folder)) {
dir.create(output_folder)
}
image_files <- list.files(input_folder, full.names = TRUE, pattern = "\\.(jpg|jpeg|png)$")
for (image_file in image_files) {
image <- image_read(image_file)
resized_image <- image_resize(image, "128x")
output_file <- file.path(output_folder, basename(image_file))
image_write(resized_image, output_file)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment