commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Damjan Jovanovic <damjan....@gmail.com>
Subject Re: working example of write to EXIF with Commons Imaging (ex Sanselan)?
Date Sun, 20 Jan 2013 15:21:48 GMT
Try something along these lines:

private static void rewriteUserComment(String fileIn, String fileOut)
throws Exception {
        TiffImageMetadata exif;
        IImageMetadata meta = Imaging.getMetadata(new File(fileIn));
        if (meta instanceof JpegImageMetadata) {
            exif = ((JpegImageMetadata)meta).getExif();
        } else if (meta instanceof TiffImageMetadata) {
            exif = (TiffImageMetadata)meta;
        } else {
            return;
        }
        TiffOutputSet outputSet = exif.getOutputSet();
        TiffOutputDirectory exifDir =
outputSet.findDirectory(TiffDirectoryConstants.DIRECTORY_TYPE_EXIF);
        exifDir.removeField(ExifTagConstants.EXIF_TAG_USER_COMMENT);
        exifDir.add(ExifTagConstants.EXIF_TAG_USER_COMMENT, "my very
own comment with " + '\u041F');

        ExifRewriter rewriter = new ExifRewriter();
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(new File(fileOut));
            rewriter.updateExifMetadataLossy(new File(fileIn), fos, outputSet);
        } finally {
            if (fos != null) {
                fos.close();
            }
        }
}


Regards
Damjan

On Wed, Jan 16, 2013 at 8:52 AM, Clement Levallois
<clementlevallois@gmail.com> wrote:
> Hi,
>
> I posted this question on StackOverflow but it might get more attention
> here:
>
> http://stackoverflow.com/questions/14341054/writing-custom-metadata-fields-to-jpeg-with-apache-commons-imaging
>
> Basically, I can't find a working example to write on a EXIF tag with
> Commons Imaging. Any help would be appreciated!
>
> Best,
>
> Clement
>
> --------------------------------------------
> Clement Levallois, PhD
> Erasmus University Rotterdam
> The Netherlands
>
> pro website<http://www.erim.eur.nl/ERIM/People/Person_Details?p_aff_id=4321>
>  / personal website <http://www.clementlevallois.net/>
>
> twitter and skype: @seinecle
> Discover the NESSHI project: http://www.nesshi.eu

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message