Created
July 30, 2024 17:14
-
-
Save ivelasq/7b45ac741d168e8bde906e0162096065 to your computer and use it in GitHub Desktop.
Resizing images using R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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