user3357059
user3357059

Reputation: 1190

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

Upvotes: 2

Views: 4142

Answers (1)

Jeroen Ooms
Jeroen Ooms

Reputation: 32978

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.

Upvotes: 4

Related Questions