commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Damjan Jovanovic (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (IMAGING-137) Can not set EXIF_TAG_EXIF_VERSION tag
Date Sun, 19 Oct 2014 07:23:33 GMT

     [ https://issues.apache.org/jira/browse/IMAGING-137?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Damjan Jovanovic resolved IMAGING-137.
--------------------------------------
       Resolution: Fixed
    Fix Version/s: 1.0

exifDirectory.add(ExifTagConstants.EXIF_TAG_EXIF_VERSION, 0, 2, 2, 1);
should work now. Resolving fixed.

> Can not set EXIF_TAG_EXIF_VERSION tag
> -------------------------------------
>
>                 Key: IMAGING-137
>                 URL: https://issues.apache.org/jira/browse/IMAGING-137
>             Project: Commons Imaging
>          Issue Type: Bug
>          Components: Format: TIFF
>    Affects Versions: 1.0
>         Environment: java 1.7.0_55  Commons-Imaging (build date is 3/25/2014)
>            Reporter: Ted Troccola
>              Labels: features
>             Fix For: 1.0
>
>
> I am unable to set EXIF_TAG_EXIF_VERSION.
> I am using Maven with the following settings (the build date is 3/25/2014):
> <dependency>
>       <groupId>org.apache.commons</groupId>
>       <artifactId>commons-imaging</artifactId>
>       <version>1.0-SNAPSHOT</version>
>       <scope>compile</scope>
>    </dependency>
>    <repository>
>       <id>apache.snapshots</id>
>       <url>http://repository.apache.org/snapshots/</url>
>    </repository>
> I get exceptions because it expects only 1 byte.
> If I debug and inspect the metadata for a JPG file with proper Exif data, it shows 4
bytes (48,50,50,48). This is consistent with this reference
> Here is my code. To run, change the file names and run.
> import java.io.BufferedOutputStream;
> import java.io.File;
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.io.OutputStream;
> import java.util.List;
> import org.apache.commons.imaging.ImageReadException;
> import org.apache.commons.imaging.ImageWriteException;
> import org.apache.commons.imaging.Imaging;
> import org.apache.commons.imaging.common.IImageMetadata;
> import org.apache.commons.imaging.common.IImageMetadata.IImageMetadataItem;
> import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata;
> import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter;
> import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
> import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;
> import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory;
> import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet;
> public class ExifExample
> {
>     public static void logImageMetaData(final File jpgImageFile) throws ImageReadException,
IOException
>     {
>         // Get all metadata stored in Exif format (i.e., from JPEG or TIFF).
>         final IImageMetadata metadata = Imaging.getMetadata(jpgImageFile);
>         if (metadata instanceof JpegImageMetadata)
>         {
>             final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
>             final List<IImageMetadataItem> items = jpegMetadata.getItems();
>             for (int i = 0; i < items.size(); i++)
>             {
>                 final IImageMetadataItem item = items.get(i);
>                 System.out.println("    "
>                         + "item: " + item);
>             }
>         }
>     }
>     private static TiffOutputSet getMetadata(final File jpegImageFile) throws ImageReadException,
IOException, ImageWriteException
>     {
>         TiffOutputSet outputSet = null;
>         // metadata might be null if no metadata is found.
>         final IImageMetadata metadata = Imaging.getMetadata(jpegImageFile);
>         final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
>         if (null != jpegMetadata)
>         {
>             // Exif might be null if no Exif metadata is found.
>             final TiffImageMetadata exif = jpegMetadata.getExif();
>             if (null != exif)
>             {
>                 /* TiffImageMetadata class is immutable (read-only).
>                  * TiffOutputSet class represents the Exif data to write.
>                  *
>                  * Usually, we want to update existing Exif metadata by changing
>                  * the values of a few fields, or adding a field.
>                  * 
>                  * In these cases, it is easiest to use getOutputSet() to
>                  * start with a "copy" of the fields read from the image.
>                  */
>                 outputSet = exif.getOutputSet();
>             }
>         }
>         return outputSet;
>     }
>     public static void writeExifData(File jpegImageFile, File destImageFile) throws IOException,
ImageReadException, ImageWriteException
>     {
>         try (OutputStream os = new BufferedOutputStream(new FileOutputStream(destImageFile)))
>         {
>             TiffOutputSet outputSet = new TiffOutputSet();
>             // Create the Exif directory tags
>             final TiffOutputDirectory exifDirectory = outputSet.getOrCreateExifDirectory();
>             /*
>              * TODO: How do you set ExifVersion
>              * 
>              * Exception in thread "main" org.apache.commons.imaging.ImageWriteException:
Tag expects 1 value(s), not 4
>                at org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory.add(TiffOutputDirectory.java:91)
>                at com.ttinc.util.exif.ExifExample.writeExifData(ExifExample.java:81)
>                at com.ttinc.util.exif.ExifExample.main(ExifExample.java:91)
>              */
>             exifDirectory.add(ExifTagConstants.EXIF_TAG_EXIF_VERSION, "0221".getBytes());
>             new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os, outputSet);
>         }
>     }
>     public static void main(String args[]) throws Exception
>     {
>         File destinationImageFile = new File("C:\\temp\\DestImage.jpg");
>         writeExifData(new File("C:\\temp\\SourceImage.jpg"), destinationImageFile);
>         logImageMetaData(destinationImageFile);
>     }
> }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message