Hi Ted,

Thanks for providing useful background, and sample code. From what I could 
understand, we would need to figure out where this File Property title is 
coming from, if not from XPTITLE (or it could be derived from XPTITLE combining 
with another field...).

Shouldn't be too hard to fix. For issues like this, the hardest part if finding 
a specification or documentation that explains things (or worse when we find 
docs that contradict each other :). Oh, and also finding example images.

Could you create a JIRA for this, please? If you have small images that can be 
added to the project, then we can use these when writing unit tests too.

Cheers
Bruno

    On Saturday, 8 January 2022, 06:17:37 am NZDT, 
ted.carr...@btinternet.com.INVALID <ted.carr...@btinternet.com.invalid> wrote:  
 
 I have been looking into this area and been a bit puzzled by what is
happening.  Something strange happens with the Title and Subject fields on
Windows when writing IPTC fields (while this is slightly outside the scope
of Apache Imaging, there is a related issue with how Apache Imaging updates
the Windows Title field – see later.)

 

There is a difference between the Title “File Property” (available in
Windows display),and the XPTITLE(MicrosoftTagConstants.EXIF_TAG_XPTITLE)
metadata field in EXIF. Windows is deciding what to put in File Properties –
it is not a straight mapping between fields and properties. 

 

(I am using ICAFE to write IPTC fields and then using Apache Imaging for the
EXIF fields.)  When the IPTC field Caption / Description field is written,
and the Title Property is currently blank , then Windows (I believe),
decides to put the Caption / Description  into the Title “File Property” for
Windows, not the Subject field.  If Title File Property is not blank, then
the Caption / Description is written to the Subject File Property, as
expected.  

So if you update the  IPTC OBJECT_NAME and CAPTION/DESCRIPTION, it is
possible get CAPTION/DESCRIPTION in both fields – I think this is what you
are seeing. 

 

I think this is related to an Apache Imaging issue that it is not possible
to overwrite the Windows Title “File Property” using Apache Imaging, if
there is already a value present in the Title “File Property”. It appears
that updating XPTITLE(MicrosoftTagConstants.EXIF_TAG_XPTITLE) through Apache
Imaging does not trigger an update of the Title “File Property”.  The result
with be a File with the XPTITLE metadata which differs from the Title
showing in Windows.  It is very easy to test this using sample code e.g.
(I will raise an issue on Jira – depending on feedback on this point.)

 

/**

    *  

    * @param jpegImageFile - source image file

    * @param dst - destination image file

    * @throws IOException - IO exception

    * @throws ImageReadException - Read exception

    * @throws ImageWriteException - write exception

    */

    public static boolean updateWindowsFields(final File jpegImageFile,
final File dst)

            throws IOException, ImageReadException, ImageWriteException {

 

        try (FileOutputStream fos = new FileOutputStream(dst);

            OutputStream os = new BufferedOutputStream(fos)) {

            TiffOutputSet outputSet = null;

            // note that metadata might be null if no metadata is found.

            final ImageMetadata metadata =
Imaging.getMetadata(jpegImageFile);

            final JpegImageMetadata jpegMetadata = (JpegImageMetadata)
metadata;

            if (null != jpegMetadata) {

                // note that exif might be null if no Exif metadata is
found.

                final TiffImageMetadata exif = jpegMetadata.getExif();

                if (null != exif) {

                    outputSet = exif.getOutputSet();

                }

            }

 

            // if file does not contain any exif metadata, we create an
empty

            // set of exif metadata. Otherwise, we keep all of the other

            // existing tags.

            if (null == outputSet) {

                outputSet = new TiffOutputSet();

            }

 

            final TiffOutputDirectory rootDir =
outputSet.getOrCreateRootDirectory();

            rootDir.removeField(MicrosoftTagConstants.EXIF_TAG_XPTITLE);

            rootDir.add(MicrosoftTagConstants.EXIF_TAG_XPTITLE, "new
title");

 

            rootDir.removeField(MicrosoftTagConstants.EXIF_TAG_XPSUBJECT);

            rootDir.add(MicrosoftTagConstants.EXIF_TAG_XPSUBJECT, "new
subject");

            //

            rootDir.removeField(MicrosoftTagConstants.EXIF_TAG_XPCOMMENT);

          rootDir.add(MicrosoftTagConstants.EXIF_TAG_XPCOMMENT, "new
comment");

            //

            rootDir.removeField(MicrosoftTagConstants.EXIF_TAG_XPKEYWORDS);

            rootDir.add(MicrosoftTagConstants.EXIF_TAG_XPKEYWORDS,
"key1;key2");

            //

            rootDir.removeField(MicrosoftTagConstants.EXIF_TAG_RATING);

            rootDir.add(MicrosoftTagConstants.EXIF_TAG_RATING, (short) 4);

            //

            rootDir.removeField(MicrosoftTagConstants.EXIF_TAG_XPAUTHOR);

            rootDir.add(MicrosoftTagConstants.EXIF_TAG_XPAUTHOR, "new
author");

 

            new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os,

                    outputSet);

            return true;

        }

        catch(Exception e)

        {

            return false;

        }

 

    }

 

 

On 2017/03/03 13:46:52 László Fenyvesi wrote: 
> Dear Friends, 
> I'm using Christopher Blunck's code to copy iptc/exif metadata: 
>
http://mail-archives.apache.org/mod_mbox/incubator-sanselan-dev/200811.mbox/
%3c5609ed95-e659-4de7-9ea0-ea2dbb76e...@thebluncks.com%3E

> (Sanselan=Imaging) 
> It usually works fine but fails on a lot of jpgs. 
> E.g.: 
> Enriched jpg: 
>      Title: 'Mouth checkup' 
>      Subject: 'Close-up of patient\u2019s open mouth before oral checkup
with 
> mirror near by' 
> Result jpg: 
>      Title: 'Close-up of patient?s open mouth before oral checkup with 
> mirror near by' 
>      Subject: 'Close-up of patient?s open mouth before oral checkup with 
> mirror near by' 
> 
> Here are the pics: 
>
http://movelex.hu/fenyoapa/user_commons_apache_org_imaging/iptc_exif_copy.ht
ml 
> 
> As you can see the result's Title and Subject became the same and \u2019 
> became ?. 
> 
> Can anybody tell me how to fix this? 
> Thank you. 
> 
> --------------------------------------------------------------------- 
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org 
> For additional commands, e-mail: user-h...@commons.apache.org 
> 
> 

  

Reply via email to