Uploaded image for project: 'Commons Imaging'
  1. Commons Imaging
  2. IMAGING-170

TIFF image gains significant size using TiffImageWriterLossless

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 1.0-alpha1
    • None
    • Format: TIFF
    • None
    • System: Fedora release 21, kernel version: 3.18.7-200.fc21.x86_64, JAVA: openjdk version "1.8.0_31", IDE: Eclipse Kepler 2, Build id: 20140224-0627

    Description

      Good afternoon,
      I am posting an issue report as suggested by mr Benedikt Ritter. It's my first issue report and I've just recently started using the Commons Imaging, so please go easy on me.
      ------------------------------------------------
      Using Commons Imaging I am reading a Tiff image (will attempt to attach it to this ticket), then I remove a tag (Focal Plane Resolution Unit) and then I save the new TiffOutputSet to the system using TiffImageWriterLossless.

      The original image is 15MB, the new image (with the Tag removed) is 28MB.

      Here's how I do it:

      RemoveTag.java
      import java.awt.image.BufferedImage;
      import java.io.File;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.io.OutputStream;
      import java.util.HashMap;
      import java.util.List;
      import java.util.Map;
      
      import org.apache.camel.Exchange;
      import org.apache.commons.imaging.ImageFormats;
      import org.apache.commons.imaging.ImageReadException;
      import org.apache.commons.imaging.ImageWriteException;
      import org.apache.commons.imaging.Imaging;
      import org.apache.commons.imaging.common.ImageMetadata;
      import org.apache.commons.imaging.formats.tiff.TiffField;
      import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
      import org.apache.commons.imaging.formats.tiff.write.TiffImageWriterLossless;
      import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory;
      import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet;
      
      File tInputFile = new File("/home/rem/TEMP/tags.original.tif");
      File toutputFile = new File("/home/rem/TEMP/tags.new.tif");
      final BufferedImage image = Imaging.getBufferedImage(tInputFile);
      
      ImageMetadata tMetadata = Imaging.getMetadata(tInputFile);
      TiffImageMetadata imageMetadata = (TiffImageMetadata) tMetadata;
      outputSet = imageMetadata.getOutputSet();
      
      TiffOutputDirectory exifDirectory = outputSet.getExifDirectory(); 
      exifDirectory.removeField(41488);
      
      ImageFormats format = ImageFormats.TIFF;
      Map<String, Object> params = new HashMap<String, Object>();
      BufferedImage image = Imaging.getBufferedImage(tInputFile);
      byte[] bytes = Imaging.writeImageToBytes(image, format, params);
      
      TiffImageWriterLossless writerLossLess = new TiffImageWriterLossless(bytes);
      writerLossLess.write(os, outputSet);
      

      Attachments

        1. kwf00346.tif
          3.54 MB
          Remigiusz Malessa
        2. Imaging_170_2015_09_21.patch
          11 kB
          Gary Lucas

        Activity

          People

            Unassigned Unassigned
            rem Remigiusz Malessa
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: