I was working on a project that involved reading many jpeg images into R and combining them into a single plot. However, there are some images that would be rotated incorrectly after import. This is what I see if I open the file on my computer
But when I read the image into R, it's rotated. Here's a reproducible example with a link to the sample image
library(imager)
url <- "https://raw.githubusercontent.com/MrFlick/readexif/main/inst/extdata/LookUp.jpg"
download.file(url, "sample.jpg", mode="wb")
img <- load.image("sample.jpg")
plot(img)
(note that the problem does NOT occur if you read the version of the image that's downloaded from imgur url <- "https://i.stack.imgur.com/7pS4x.jpg")
How can I correctly read such images into R without "fixing" each one individually?



