question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Beginner questions: displaying tiff not successfull with imageio-jpeg; metadata in JPEG not read.

See original GitHub issue

Sorry: I could not find a forum, mailing list or something alike. As I do think these are beginner questions and not bugs, I put 2 in one post thereby only “abusing” one post instead of two.

I just started using the TwelveMonkeys imageIO library, using the 3.6 version, and have 2 issues.

Not being able to display tiff when using imageio-jpeg. In my project in my build.gradle.kts I have the following:

    // Twelve monkeys imageio (supports bmp, jpeg, jpeg-2000, PNM (PBM/PGM/PPM/PAM), PSD, TIFF, HDR, IFF, PCX
    // PICT, SGI, TGA, ICNS, ICO & CUR, SVG, WMF)
    implementation("com.twelvemonkeys.imageio:imageio-core:3.6")
    implementation("com.twelvemonkeys.imageio:imageio-metadata:3.6")
    //
    implementation("com.twelvemonkeys.imageio:imageio-jpeg:3.6")
    //
    implementation("com.twelvemonkeys.imageio:imageio-tiff:3.6")
    //implementation("com.twelvemonkeys.imageio:imageio-psd:3.6")
    implementation("com.twelvemonkeys.imageio:imageio-pnm:3.6")
    implementation("com.twelvemonkeys.imageio:imageio-pcx:3.6")
    implementation("com.twelvemonkeys.imageio:imageio-sgi:3.6")
    implementation("com.twelvemonkeys.imageio:imageio-tga:3.6")
    implementation("com.twelvemonkeys.imageio:imageio-icns:3.6")
    implementation("com.twelvemonkeys.imageio:imageio-hdr:3.6")

My java project reads images and creates previews of them. When using the imageio-jpeg no tiff previews are created and when opening them from my app in a (fullscreen) jframe I do get a java.lang.NullPointerException. Somehow the new ImageIcon, with or without resizing, is no longer working for tiffs with imageio-jpeg enabled. When disabling the imageio-jpeg in my build.gradle.kts, I do see tiff previews and I am able to display tiff images full screen. Is this a bug or some beginner mistake?

Reading metadata in jpegs does not work I thought that EXIFReader is deprecated and that TIFFReader should be used for all images when reading metadata.

So I created a new test method in my project and did

try {
    Directory metadata = new TIFFReader().read(new FileImageInputStream(file));
    for (Entry entry: metadata) {
        //logger.info("identifier {} fieldname {} value {} valueString {}, typename {}", entry.getIdentifier(), entry.getFieldName(), entry.getValue(), entry.getValueAsString(), entry.getTypeName());
        logger.info("fieldname {} value {}", entry.getFieldName(), entry.getValue());
    }
} catch (IOException e) {
    e.printStackTrace();
}

When I used this on tiff images it works great. When using on jpg’s I get: javax.imageio.IIOException: Invalid TIFF byte order mark '��', expected: 'II' or 'MM'

This is happening on all jpegs from multiple cameras and sources. I fully understand that it is my fault, but I could not find how to get my metadata from my jpegs?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
haraldkcommented, Aug 7, 2020

The fact that you don’t have all the iff/pcx/pict/pnm/sgi/tga formats available and only either the TIFF or the JPEG plugin (only the TwelveMonkeys JPEG plugin supports jpeg-lossless), suggests again that the problem is the bundling as mentioned in this comment. The fat JAR packager does not correctly merge entries in META-INF/services, meaning you are left with only a single plugin.

– Harald K

2reactions
Schmidorcommented, Aug 7, 2020

We had those services issues back when we did create fat jars for a webstart. Our merging code for gradle might be helpfull 😃

task fatJarWebstart {
  doLast {
    def serviceDir = file("$buildDir/tmp/bigJar/META-INF/services")
    serviceDir.deleteDir()
    serviceDir.mkdirs()
    // copy all service files from deps to buildDir
    for(file in configurations.runtimeClasspath) {
      zipTree(file).matching{ include 'META-INF/services/*' }.each { f ->
        new File(serviceDir, f.name) << f.getText("UTF-8") + '\n'
      }
    }

    ant.jar (destfile: 'build/webstart/lib/libs.jar', duplicate: 'preserve'){
      String cp = configurations.runtimeClasspath.asPath.toString()
      cp.tokenize( ';' ).each {
        def jar = file(it)
        if (!jar.name.startsWith( 'bc' )){
          zipfileset (src: jar.path){
            exclude (name: 'META-INF/*.SF')
            exclude (name: 'META-INF/*.DSA')
            exclude (name: 'META-INF/*.RSA')
            exclude (name: 'META-INF/README.*')
            exclude (name: 'META-INF/NOTICE.*')
            exclude (name: 'META-INF/NOTICE')
            exclude (name: 'META-INF/LICENSE.*')
            exclude (name: 'META-INF/LICENSE')
            exclude (name: 'META-INF/MANIFEST.MF')
            exclude (name: 'META-INF/maven/**')
          }
        }
      }
      delegate.manifest {
        attribute(name: 'Permissions', value: 'all-permissions')
        attribute(name: 'Codebase', value: '*')
        attribute(name: 'Implementation-Vendor', value: 'Sun Microsystems, Inc.')
        attribute(name: 'Implementation-Title', value: 'com.sun.media.imageio')
        attribute(name: 'Implementation-Version', value: '1.1')
        attribute(name: 'Specification-Vendor', value: 'Sun Microsystems, Inc.')
        attribute(name: 'Specification-Title', value: 'Java Advanced Imaging Image I/O Tools')
        attribute(name: 'Specification-Version', value: '1.1')
        attribute(name: 'Extension-Name', value: 'com.sun.media.imageio')
      }
    }
    ant.jar(update: "true", destfile: 'build/webstart/lib/libs.jar') {
      fileset(dir: "$buildDir/tmp/bigJar", includes: 'META-INF/services/*')
    } 
  }
}

There were some specifics for jai-imageio, which needs some manifest entries, and not including bouncy castle in the merging to preserve the signed security provider classes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Image Metadata not copied from a jpeg to a tif file, using Java ...
When I try to copy the contents of a “.jpg” file to a new “.tif” file, the IIOMetadata is not preserved. The main...
Read more >
GeoServer fails to read a JPEG compressed TIFF with alpha ...
Indeed, according to this, GeoServer cannot read RGBA TIFF with JPEG compression. However, I found a solution, based on gdal_translate ...
Read more >
How to write simple Exif metadata to JPEG from scratch. #586
I'm successfully reading, processing, and writing JPEG metadata using Java Image I/O. It's works fine. I set my image reader to ignore reading...
Read more >
imageio Documentation - Read the Docs
When creating a GIF using imageio the resulting images can get quite heavy, as the created GIF is not optimized. This.
Read more >
Image Basics – Image Processing with Python - Data Carpentry
Explain the characteristics of the BMP, JPEG, and TIFF image formats. ... which cannot easily be achieved with the limited set of basic...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found