Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MiniMagick::Image#mime_type outputting wrong value for PDFs with IM 7.0.8.64 #486

Closed
adamcreekroad opened this issue Sep 9, 2019 · 3 comments

Comments

@adamcreekroad
Copy link

adamcreekroad commented Sep 9, 2019

I'm not sure if this is a bug here that is just now manifesting, or a bug in IM (or both?). According to their changelog, it looks like they somewhat recently revised the PDF reader.

Given a PDF exported by Adobe Illustrator, the identify command now outputs
Mt Moon.pdf AI 810x1242 810x1242+0+0 16-bit ColorSeparation CMYK 3.83776MiB 0.010u 0:00.010

What it used to output is
Mt Moon.pdf PDF 810x1242 810x1242+0+0 16-bit ColorSeparation CMYK 3.83776MiB 0.400u 0:00.389

With -verbose added on, they both give the correct mime-type:
Image: Mt Moon.pdf Format: AI (Adobe Illustrator CS2) Mime type: application/pdf

Image: Mt Moon.pdf Format: PDF (Portable Document Format) Mime type: application/pdf

The mime_type method in MiniMagick doesn't actually use that value, it takes the format (AI or PDF) and just adds it onto image/.

def mime_type
  "image/#{self["format"].downcase}"
end

So what we now get is image/ai instead of image/pdf. Even image/pdf isn't technically right, it should be application/pdf

An easy way to get the proper value

def mime_type
  self["data"]["mimeType"]
end

This would of course be breaking to everyone expecting the old behavior of outputting image/pdf.

@janko
Copy link
Member

janko commented Sep 9, 2019

That was a poor decision to build the MIME type this way (by prepending image/), as ImageMagick can work with lots of formats that don't have image/* MIME types, like PDFs that you mentioned.

It should get changed to output correct values, maybe with a new major release then.

@hwo411
Copy link

hwo411 commented Oct 16, 2023

The same problem is with svg, actually.

It says image/svg while it should be image/svg+xml.

The solution from the original method indeed works. Would be great to have this fixed.

@janko
Copy link
Member

janko commented Jun 7, 2024

This cannot be fixed in a backwards compatible way, as

def mime_type
  self["data"]["mimeType"]
end

will be significantly slower, because the whole image has to be read, unlike with current implementation where only the magic header needs to be read.

I don't think ImageMagick is sufficiently good for determining MIME types, there are Marcel and MimeMagic that are able to do this by just reading the header file. So, I will be deprecating MiniMagick::Image#mime_type.

@janko janko closed this as completed in ac2a94a Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants