1

what's the most painless way to programmatically open a PNG file on my computer, rotate it 90 degrees, then save it as another PNG file - with no loss of quality and no other changes? it's a five-second task in microsoft paint but all of the plotting, raster, image, device answers to related SO questions have me confused about the simplest way to do this? thanks

enter image description here

enter image description here

Anthony Damico
  • 5,779
  • 7
  • 46
  • 77

2 Answers2

4

Try package magick :

library(magick)
newlogo <- image_read("https://www.r-project.org/logo/Rlogo.png")
newlogo <- image_scale(newlogo, "400x400") # logo is too big

# rotate
image_rotate(newlogo, 90)

# save    
image_rotate(newlogo, 45) %>% image_write("newlogoRotated.png")

I think that's the easiest way !

Victorp
  • 13,636
  • 2
  • 51
  • 55
1

It's also possible to use the Bioconductor package EBImage, as in the following example.

library(EBImage)

# open
img <- readImage("https://www.r-project.org/logo/Rlogo.png")

# rotate
img <- rotate(img, 90)

# save    
writeImage(img, "Rlogo.png")
aoles
  • 1,525
  • 10
  • 17