2

I want to modify the metadata of some types of images (png, jpeg or gif) and I found a a code that works very well for PNG images on this topic, provided by haraldK. When I try to run it on a jpg image though, it throws this error : javax.imageio.IIOException: JFIF APP0 must be first marker after SOI. The error is thrown when arriving on the line IIOImage image = reader.readAll(0, null);

What can I do to get this working ?

Thanks in advance for your answer.

Peter suib
  • 108
  • 2
  • 10
  • You can try my [JPEG plugin for ImageIO](https://github.com/haraldk/TwelveMonkeys#jpeg), it will most likely handle your image fine, with no code changes (only new dependencies on class path). – Harald K Mar 14 '19 at 12:05
  • So I downloaded the jars for jpeg and TIFF that are showed under 'Manual dependency example', is it enough to work ? And when you mean no code changes it means that I can use the exact same code you proposed on the subject I mentionned ? – Peter suib Mar 16 '19 at 17:48
  • You need to place the jars on class path. If your application is a web app, you need to read the part about web apps. Otherwise it should be enough. You can check the class of the reader. It should be com.twelvemonkeys...JPEGImageReader. If it is, and it does not work, I need to see the JPEG file to say why. – Harald K Mar 16 '19 at 18:47

1 Answers1

0

The problem you face is the JPEG standard did not define a file format. Several file formats appeared. E.g. JFIF. EXIF. SPIFF. These formats represent metadata in different ways. Apparently the library you are trying to use only supports the JFIF file format. Apparently your library only supports the JFIF format while you have a file in a different format (likely EXIF).

So you need a library that supports your file format or you need to modify the library you have to work with whatever file format you have. That could be a fairly substantial change.

user3344003
  • 20,574
  • 3
  • 26
  • 62
  • Ok, so I found the [Apache Commons Library (Sanselan)](https://commons.apache.org/proper/commons-imaging/download_sanselan.cgi) but I don't know how it works, do you have any idea ? Or any other library that works fine ? – Peter suib Mar 14 '19 at 07:33
  • 2
    The standard JPEG plugin for ImageIO supports both JFIF and Exif JPEGs. However, both these specs *require* that "their" APP segments being the first segment in the stream. Most readers will be lenient about this, but the standard ImageIO plugin is strict and throws the exception seen by the OP if this is not the case. – Harald K Mar 14 '19 at 12:08