coobird / thumbnailator

Thumbnailator - a thumbnail generation library for Java
MIT License
5.08k stars 780 forks source link

javax.imageio.IIOException: Invalid JPEG file structure: two SOF markers #210

Open dacr opened 11 months ago

dacr commented 11 months ago

Expected behavior

Image being resized, recompressed

Actual behavior

An exception is raised : javax.imageio.IIOException: Invalid JPEG file structure: two SOF markers for a particular photo, success with all previous ones. The original photo is here couldn't upload it as its size is over 10Mb (26Mb).

The photo can be loaded with various software :

scala> {
     | Thumbnails
     |           .of(input)
     |           .useExifOrientation(true)
     |           .size(1920, 1920)
     |           .keepAspectRatio(true)
     |           .outputQuality(0.8)
     |           .allowOverwrite(false)
     |           .toFile(output)
     | }
javax.imageio.IIOException: Unsupported marker type 0x7a
  at java.desktop/com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
  at java.desktop/com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1382)
  at java.desktop/com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:1162)
  at net.coobird.thumbnailator.tasks.io.InputStreamImageSource.readImage(Unknown Source)
  at net.coobird.thumbnailator.tasks.io.InputStreamImageSource.read(Unknown Source)
  at net.coobird.thumbnailator.tasks.io.FileImageSource.read(Unknown Source)
  at net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask.read(Unknown Source)
  at net.coobird.thumbnailator.Thumbnailator.createThumbnail(Unknown Source)
  at net.coobird.thumbnailator.Thumbnails$Builder.toFile(Unknown Source)
  ... 66 elided

Steps to reproduce the behavior

Thumbnails
          .of(input)
          .useExifOrientation(true)
          .size(1920, 1920)
          .keepAspectRatio(true)
          .outputQuality(0.8)
          .allowOverwrite(false)
          .toFile(output)

Environment

dacr commented 11 months ago

Found this hint : https://stackoverflow.com/questions/31094267/invalid-jpeg-file-structure-two-soi-markers-error