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

JpegImageMetadata getEXIFThumbnail only works on Jpeg thumbnails stored as Tiff images.

    XMLWordPrintableJSON

Details

    Description

      JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
      BufferedImage image = jpegMetadata.getEXIFThumbnail();

      Above code seaches tiff directory structure but only searches for dir.getTiffImage() and only checks if tiffImageData is null. Jpeg files which have Jpeg thumbs stored as JpegImageData do not work.

      I was able to fix this with following code:

      import org.apache.sanselan.formats.tiff.JpegImageData;
      import javax.imageio.ImageIO;
      import java.io.ByteArrayInputStream;
      
      	public BufferedImage getEXIFThumbnail() throws ImageReadException,
      			IOException {
      		ArrayList dirs = exif.getDirectories();
      		for (int i = 0; i < dirs.size(); i++) {
      			TiffImageMetadata.Directory dir = (TiffImageMetadata.Directory) dirs
      					.get(i);
      			// Debug.debug("dir", dir);
      			BufferedImage image = dir.getThumbnail();
      			if (null != image)
      				return image;
                              JpegImageData jpegImageData = dir.getJpegImageData();
                              if(jpegImageData!=null){
                                  ByteArrayInputStream input = new ByteArrayInputStream(jpegImageData.data);
                                  image = ImageIO.read(input);
                                  if (image!=null)
                                      return image;
                              }
      		}
      
      		return null;
      	}
      

      Attachments

        1. jamesEJ_jpeg_patch.txt
          1 kB
          James E-J
        2. img_F028c_small.jpg
          69 kB
          James E-J

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jamedjo James E-J
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 20m
                  20m
                  Remaining:
                  Remaining Estimate - 20m
                  20m
                  Logged:
                  Time Spent - Not Specified
                  Not Specified