For loop with multiple variables in R

Viewed 35

I'm new to working with images, and i'm trying to resize files en masse.

filename format width height colorspace matte filesize density Megapixels maxparam factor new height new width
C:\Users\Darren\Downloads\KA/KA - 5KEK1222AER_1.jpg JPEG 4637 6494 sRGB FALSE 2293580 96x96 30.112678 6494 0.315676009 20571.72488 14689.11122
C:\Users\Darren\Downloads\KA/KA - 5KEK1222AOB_1.png PNG 4651 6525 sRGB TRUE 10801085 118x118 30.347775 6525 0.314176245 20768.59756 14803.79268
C:\Users\Darren\Downloads\KA/KA - 5KEK1222ASX_1.jpg JPEG 4601 6503 sRGB FALSE 2556722 96x96 29.920303 6503 0.31523912 20628.78488 14595.26976
C:\Users\Darren\Downloads\KA/KA - 5KEK1222AWH_1.jpg JPEG 4637 6494 sRGB FALSE 1504188 300x300 30.112678 6494 0.315676009 20571.72488 14689.11122
C:\Users\Darren\Downloads\KA/KA - 5KFC3516AAC_1.jpg TIFF 4296 5526 sRGB TRUE 43705164 300x300 23.739696 5526 0.370973579 14895.93951 11580.33951
C:\Users\Darren\Downloads\KA/KA - 5KFC3516ACU_1.jpg TIFF 4296 5526 sRGB TRUE 46561548 300x300 23.739696 5526 0.370973579 14895.93951 11580.33951
C:\Users\Darren\Downloads\KA/KA - 5KFC3516AER_1.jpg TIFF 4296 5526 sRGB TRUE 44582636 300x300 23.739696 5526 0.370973579 14895.93951 11580.33951
C:\Users\Darren\Downloads\KA/KA - 5KFC3516AOB_1.jpg TIFF 4296 5526 sRGB TRUE 41562732 300x300 23.739696 5526 0.370973579 14895.93951 11580.33951
C:\Users\Darren\Downloads\KA/KA - 5KFP0719AAC_1.jpg TIFF 4381 6269 sRGB FALSE 122123560 300x300 27.464489 6269 0.327005902 19170.9078 13397.31171
C:\Users\Darren\Downloads\KA/KA - 5KFP0919AAC_1.jpg TIFF 4381 6269 sRGB FALSE 125133076 300x300 27.464489 6269 0.327005902 19170.9078 13397.31171
C:\Users\Darren\Downloads\KA/KA - 5KSB4027AAC_1.jpg JPEG 4096 5456 sRGB FALSE 4705371 300x300 22.347776 5456 0.375733138 14520.94439 10901.35415
C:\Users\Darren\Downloads\KA/KA - 5KSB4027ACU_1.jpg JPEG 4096 5456 sRGB FALSE 4848262 300x300 22.347776 5456 0.375733138 14520.94439 10901.35415
C:\Users\Darren\Downloads\KA/KA - 5KSB4027ADR_1.jpg JPEG 4096 5456 sRGB FALSE 1378979 300x300 22.347776 5456 0.375733138 14520.94439 10901.35415
C:\Users\Darren\Downloads\KA/KA - 5KSB4027AER_1.jpg JPEG 4096 5456 sRGB FALSE 4822582 300x300 22.347776 5456 0.375733138 14520.94439 10901.35415
C:\Users\Darren\Downloads\KA/KA - 5KSB4027AOB_1.jpg JPEG 4096 5456 sRGB FALSE 4916966 300x300 22.347776 5456 0.375733138 14520.94439 10901.35415
C:\Users\Darren\Downloads\KA/KA - 5KSB4027APT_1.jpg JPEG 4096 5456 sRGB FALSE 1397586 300x300 22.347776 5456 0.375733138 14520.94439 10901.35415
C:\Users\Darren\Downloads\KA/KA - 5KSB4027AVB_1.jpg JPEG 4096 5456 sRGB FALSE 4743516 300x300 22.347776 5456 0.375733138 14520.94439 10901.35415

This table represents all images downloaded from an S3 bucket which exceeds the megapixel limit for a website. I am hoping to sequence along "filename" and read the image, then resize it by a factor of "factor". My attempted code was as follows:

for (i in seq_along(calculator$filename)){function(x) image_read(x)%>%image_resize(., "factor" )%>%image_write(.,paste(x))}

The only output I get is 'i' as an integer of length 17.

I feel like i'm missing some kind of object creation and have some incorrect syntax. Can anybody fix my code?

0 Answers
Related