ropensci / magick

Magic, madness, heaven, sin
https://docs.ropensci.org/magick
Other
459 stars 64 forks source link

**** Error: ICCbased space /N value does not match the ICC profile. #189

Closed ksw9 closed 5 years ago

ksw9 commented 5 years ago

Hi, I am using magick to read a PDF file, modify it, and resave as a reformatted PDF. For now, I am just trying to test reading/writing the same PDF to make sure I can complete the loop. Unfortunately, the PDF is protected data, so I cannot share the problem.

# Read in PDF.
img <- image_read("example.pdf"[1], density = "150x150")

# Write PDF.
image_write(img2, 'test.pdf', format = 'pdf', density = "300x300")

# Try rereading with magick. 
image_read('test.pdf')

# I get the error: 
  **** Error: ICCbased space /N value does not match the ICC profile.
                 Using the number of channels from the profile.
                 Output may be incorrect.

Any suggestions would be great! The PDF I have saved looks correct, but for some reason cannot be re-read into magick (or using other PDF read tools in R and python). Any suggestions would be great. Thank you in advance.

jeroen commented 5 years ago

Could you try with image_read_pdf()? Alternatively read it using pdftools like this:

library(pdftools)
img <- pdftools::pdf_render_page("yourname.pdf")
magick::image_read(img)

I'm not sure it is possible to write pdf files because the document contents will get converted to a big bitmap image when reading in magick.

jeroen commented 5 years ago

Closing this due to lack of a reproducible example.

TB-Development commented 1 year ago

I have this issue as well.

Rails: 7.0.5 Ruby: 3.2.2 CarrierWave: 2.2.3

I'm using CarrierWave to process thumbnails, with ImageMagick and Ghostscript installed on the machine running the application.

This is an issue with Ghostscript processing the file, the solution for me was to convert to RGB before processing the file.

My specific error was:

  **** Error: ICCbased space /N value does not match the ICC profile.
                 Using the number of channels from the profile.
                 Output may be incorrect.

The error went away for me within carrierwave by crafting my uploader as follows, which includes converting the file to the RGB Colorspace before processing it with cover:

class VersionUploader < CarrierWave::Uploader::Base
  include CarrierWave::Compatibility::Paperclip
  include CarrierWave::MiniMagick
  storage :fog

  # @doc Just to persist the same file path that the old image uploader was using
  def paperclip_path
    "shared/system/:class/:attachment/:id_partition/:style/:basename.:extension"
  end

  def content_type_allowlist
    [/image\//, /application\//]
  end

  version :thumb do
    process :flatten_and_convert_to_rgb
    process :cover
    process resize_to_fill: [200,200]
  end

  def cover
    MiniMagick::Image.new(path).pages.count.times.map{ |page_number|
      ImageProcessing::MiniMagick.source(path).convert("jpg").loader(page: page_number).call
    }.first
  end

  def flatten_and_convert_to_rgb
    manipulate! do |image|
      image.flatten
      image.colorspace("RGB")
      image
    end
  end
end

Sources:

https://unix.stackexchange.com/a/618980/430838