rimage-processingmagick

Error using R magick package


I am trying to save a jpeg picture in png format using the magick package in R and I'm facing an error.

Below is the error that I get using this code:

library(magick)

testPic <- "https://upload.wikimedia.org/wikipedia/commons/thumb/4/42/President_Roosevelt_-_Pach_Bros.tif/lossy-page1-165px-President_Roosevelt_-_Pach_Bros.tif.jpg"

image <- image_read(testPic)
image_info(image)
image_convert(image, format = "png", depth = NULL)
Error in magick_image_write(image, format, quality) : 
  Magick: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG `' @ warning/png.c/MagickPNGWarningHandler/1656

Solution

  • This is a bug in imagemagick. The workaround is to add strip = TRUE to image_read():

    library(magick)
    
    testPic <- "https://upload.wikimedia.org/wikipedia/commons/thumb/4/42/President_Roosevelt_-_Pach_Bros.tif/lossy-page1-165px-President_Roosevelt_-_Pach_Bros.tif.jpg"
    
    image <- image_read(testPic, strip = TRUE)
    image_info(image)
    image_convert(image, format = "png", depth = NULL)
    

    I'll try to ping upstream again to fix this.