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

Exception reading a CMYK Jpeg #40

Closed
GoogleCodeExporter opened this issue Jul 25, 2015 · 7 comments
Closed

Exception reading a CMYK Jpeg #40

GoogleCodeExporter opened this issue Jul 25, 2015 · 7 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Generate a CMYK JPG, call it selectedFile
1. Run Thumbnails.of(selectedFile).size(500, 500).toFile(thumb500File);

What is the expected output? What do you see instead?

Expected output - thumb500File created normally

Actual output: Exception raised "Incompatible color conversion"

What version of the product are you using? On what operating system? Which
version of Java (Sun/Oracle? OpenJDK?) ?

OpenJDK 7u9, Ubuntu Linux

Please provide any additional information below.

The core Java method ImageIO.read produces exactly the same exception, e.g.

BufferedImage originalImage = ImageIO.read(selectedFile);

so it looks like the issue is with Java, however other people have found 
workarounds - 
http://www.randelshofer.ch/blog/2011/08/reading-cmyk-jpeg-images-with-java-image
io/

Would it be possible to implement a workaround in Thumbnailator too? I think 
the Java issue dates back some time.

A sample JPG exhibiting the problem is attached.

Original issue reported on code.google.com by oliver.k...@gmail.com on 1 Nov 2012 at 12:59

Attachments:

@GoogleCodeExporter
Copy link
Author

Thank you for reporting this issue along with a supplemental link.

I have been able to reproduce this issue with Thumbnailator 0.4.2, and it does 
indeed appear to be a problem with the JPEG reader that is being used by Image 
I/O.

I will look into the link in a little more detail at a later time, but I would 
like to see if there are other ways of implementing a workaround rather than 
having to write an alternate JPEG reader to the one that is provided with Java.

(Image I/O does indeed have many outstanding bugs which have not been addressed 
for close to a decade...)

Once again, thank you for the detailed report.

------------------

The following is the stack trace on Ubuntu 12.04 with Oracle JDK 1.7.0_04:

  Exception in thread "main" javax.imageio.IIOException: Unsupported Image Type
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:995)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:966)
    at javax.imageio.ImageReader.read(ImageReader.java:940)
    at net.coobird.thumbnailator.tasks.io.FileImageSource.read(FileImageSource.java:144)
    at net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask.read(SourceSinkThumbnailTask.java:76)
    at net.coobird.thumbnailator.Thumbnailator.createThumbnail(Thumbnailator.java:62)
    at net.coobird.thumbnailator.Thumbnails$Builder.toFile(Thumbnails.java:2409)
    at Issue40.main(Issue40.java:15)


The following is the stacktrace on Ubuntu 12.04 and OpenJDK 1.6.0_24:

  Exception in thread "main" javax.imageio.IIOException: Incompatible color conversion
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.checkColorConversion(JPEGImageReader.java:927)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1028)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:984)
    at javax.imageio.ImageReader.read(ImageReader.java:940)
    at net.coobird.thumbnailator.tasks.io.FileImageSource.read(FileImageSource.java:144)
    at net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask.read(SourceSinkThumbnailTask.java:76)
    at net.coobird.thumbnailator.Thumbnailator.createThumbnail(Thumbnailator.java:62)
    at net.coobird.thumbnailator.Thumbnails$Builder.toFile(Thumbnails.java:2409)
    at Issue40.main(Issue40.java:15)

Original comment by coobird...@gmail.com on 11 Nov 2012 at 12:17

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Yes I guess the ideal would be to submit a patch to the JDK:

http://openjdk.java.net/contribute/

for bug

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5100094

Unfortunately I myself haven't the time to work towards that at the moment.

Original comment by oliver.k...@gmail.com on 11 Nov 2012 at 2:18

@GoogleCodeExporter
Copy link
Author

Adding a link to a question on StackOverflow regarding reading CMYK JPEG images 
using Java Image I/O:

http://stackoverflow.com/questions/2408613/problem-reading-jpeg-image-using-imag
eio-readfile-file

Original comment by coobird...@gmail.com on 16 Jul 2013 at 3:38

@GoogleCodeExporter
Copy link
Author

FYI: You can workaround this issue by using JPEGImageReader from 

https://github.com/haraldk/TwelveMonkeys

Original comment by marcus.l...@googlemail.com on 24 Oct 2013 at 8:27

@GoogleCodeExporter
Copy link
Author

Note
------
Use of "TwelveMonkeys ImageIO" fixes this particular issue.
https://github.com/haraldk/TwelveMonkeys

(Thank you for the tip, marcus!)

Original comment by coobird...@gmail.com on 21 Sep 2014 at 10:41

@Paper-Folding
Copy link

I encountered the same problem, if converting image to rgb via photoshop, the problem disappears.

@coobird
Copy link
Owner

coobird commented Mar 12, 2022

Support for CMYK JPEGs would require writing a JPEG reader that supports it, which is outside the scope of Thumbnailator. (Thumbnailator is a wrapper around the Java 2D and Image I/O APIs.)

TwelveMonkeys ImageIO provides an excellent alternative to Java's default JPEG reader/writer, which can deal with CMYK JPEGs

@coobird coobird closed this as completed Mar 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants