dragon66 / icafe

Java library for reading, writing, converting and manipulating images and metadata
Eclipse Public License 1.0
204 stars 58 forks source link

Failed modify WINDOWS_XP_TITLE info #31

Closed ivanooi closed 8 years ago

ivanooi commented 8 years ago

Hi,

this is the code.

JpegExif exif = new JpegExif(); exif.addImageField(TiffTag.WINDOWS_XP_TITLE, FieldType.BYTE, "".getBytes("UTF-16LE"));

it managed to modify Windows XP comments, subject but failed on Authors and Title. Please note that, all this fields already contained info. Ijust wanted to modify the info.

Any ideas ? Thanks

ivanooi commented 8 years ago

Really hope for your help as I use this library to create an app for volunteers... big thanks

dragon66 commented 8 years ago

@ivanooi For any Windows related tags, the FieldType should be FieldType.WINDOWSXP not FieldType.BYTE. Also you don't need to use "".getBytes("UTF-16LE"), just use the String itself. Refer to TestMetadata.java for more details.

If the above doesn't solve the problem, it may be caused by the fact that you already have fields with the same tags. In this case, in order to avoid corrupting the original image, inserting the field with the same tag will throw RuntimeException "Duplicate Tag".

To solve the problem, I have made a change to the code to allow non-critical tags to be replaced.

Please check out the latest code and try again.

ivanooi commented 8 years ago

Hi,

I just download the latest jar but.. it still failed making modification on that fields. THis is my test code :+1:

  FileInputStream fin = new FileInputStream("RW_KL20151213_hyx02_012.JPG");
  FileOutputStream fout = new FileOutputStream("thumbnailAdded.jpg");      

// TiffExif exif = new TiffExif(); JpegExif exif = new JpegExif();

  DateFormat formatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");

  exif.addImageField(TiffTag.WINDOWS_XP_AUTHOR, FieldType.WINDOWSXP, "WINDOWS_XP_AUTHOR");
  exif.addImageField(TiffTag.WINDOWS_XP_TITLE, FieldType.WINDOWSXP, "Test");//.getBytes("US-ASCII")

  Metadata.insertExif(fin, fout, exif, true);
  fin.close();
  fout.close();      

Do you need my sample photo ?

Thanks

dragon66 commented 8 years ago

@ivanooi What is the error message? Can you put your sample photo somewhere for me to test?

ivanooi commented 8 years ago

Can I email you the photo ?

There;s no error throw.

This are the few exceptions that I catch :+1:

  } catch (FileNotFoundException e) {
     e.printStackTrace();
  } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
  } catch (IOException e) {
     e.printStackTrace();
  }

Thanks again

ivanooi commented 8 years ago

Big Thanks! :+1: :100: :-D

really need your help. lot lib failed in this area. including common imaging.

dragon66 commented 8 years ago

@ivanooi I figured out what is wrong here:

The problem: 1). The photo you provided has both EXIF and XMP and both of them contain some of the common tags. The tags in XMP take precedence if in Windows, you right click the image->properties->details as I tested. So even if you have changed EXIF, some of the tag values will still be showing as before because they are the tag values contained in XMP. Only those tags which are in EXIF but not in XMP will be shown this way. If you view the metadata using a different tool, you will be able to see them in EXIF. 2). There are Unicode string fields like "Artist", "Image Description" in the photo which are treated as ASCII string. Theoretically, TIFF doesn't has a field type for Unicode string. As a result, in the process of inserting EXIF, icafe took the Unicode string as ASCII and those strings became unrecognizable. This has nothing to do with the Windows XP related tags though - I found this issue while trying to fix your problem.

The solution: 1) If you want, you can remove XMP using icafe and keep only EXIF. After that, you can insert new EXIF tags as you want - refer to TestMetadata.java on how to remove metadata.

  1. Just insert EXIF tags without touching the XMP - of course, some of them will be shadowed if viewed with Windows Explorer. This is not a problem if you don't care about it.

I have updated the code. Try again.

dragon66 commented 8 years ago

@ivanooi There are two free tools which you can use to view the EXIF metadata after you add them:

  1. JPEGSnoop
  2. XnViewMP

Download them and cross check the output image from icafe.

Hope this helps!

ivanooi commented 8 years ago

Hi, you are right! ya, some how Windows store the info in XMP! What a surprise! Look like I need to remove the XMP info.. Thanks! Thanks! Thanks!!

ivanooi commented 5 years ago

Hi,

Sorry, now these 2 fields failed to show up in Windows XP OS.... Windows Vista, 7 and 10 no problem. only Windows XP if u need the photo, let me know... Thanks again

Greenshot 2019-05-21 00 42 49

dragon66 commented 5 years ago

@ivanooi First of all, I assume you created the image by inserting the fields into Exif with Windows tags like WINDOWS_XP_TITLE etc. After that you can see it in all versions of Windows higher than Windows XP.

If that is the case, now let's do a few tests:

  1. Choose an image (Not the one you already added WINDOWS_XP_TITLE etc. tags), explore the properties of the image. If you don't see anything in the title and you can edit the title, add a new title and save the image.

  2. Save a copy of the image from step 1. Now try using ICAFE to insert WINDOWS_XP_TITLE as part of Exif metadata.

  3. Now explore the properties of the image saved in step 2 with Windows XP. Can you see the tile now? If you can which one is showing?

  4. Now explore the properties of the images saved in step 2 with any other Windows versions than XP. What do you find this time?

  5. Whatever you find in step 3 and 4, send both the images in step 1 and step 2 to my email box. I will take a look at them.

By the way, to make it safe, you can insert the title into both TiffField.WINDOWS_XP_TITLE and TiffTag.IMAGE_DESCRIPTION fields and see if it helps.

ivanooi commented 5 years ago

Hi,

Thanks for your advice. Photos sent. Basically, i had found a way to make the metadata nicely shown up in Vista, 7 and 10. No problems at all. really thanks for your help all the times.

Now only Win XP failed to display title and author...

dragon66 commented 5 years ago

@ivanooi I can't figure out what the problem is except that the image you inserted metadata with ICAFE contains unicode strings and they are included in both XMP and EXIF whereas the one you manually inserted metadata contains only Eixf with ASCII strings

It is very hard to say what is going wrong if the metadata themselves and/or encoding are different in different images.

Can you try add same metadata with same encoding as well to the original image both ways - 1. Using right-click in Windows XP->Properties and 2. With ICAFE.

ivanooi commented 5 years ago

I had tested insert only ascii but still, nothing showed up. ..

On Thu, 23 May 2019 at 09:28, dragon66 notifications@github.com wrote:

@ivanooi https://github.com/ivanooi I can't figure out what the problem is except that the image you inserted metadata contains unicode strings and they are included in both XMP and Exif whereas the one you manually inserted metadata contains only Eixf with ASCII strings.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dragon66/icafe/issues/31?email_source=notifications&email_token=ADS5AJGR3GH3SRZYUKCSUO3PWXXNNA5CNFSM4CLZGSM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWAZVBI#issuecomment-495032965, or mute the thread https://github.com/notifications/unsubscribe-auth/ADS5AJER6NLRDGNYOI7FQODPWXXNNANCNFSM4CLZGSMQ .

ivanooi commented 5 years ago

This, only ascii for title and author..

On Thu, 23 May 2019 at 09:28, dragon66 notifications@github.com wrote:

@ivanooi https://github.com/ivanooi I can't figure out what the problem is except that the image you inserted metadata contains unicode strings and they are included in both XMP and Exif whereas the one you manually inserted metadata contains only Eixf with ASCII strings.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dragon66/icafe/issues/31?email_source=notifications&email_token=ADS5AJGR3GH3SRZYUKCSUO3PWXXNNA5CNFSM4CLZGSM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWAZVBI#issuecomment-495032965, or mute the thread https://github.com/notifications/unsubscribe-auth/ADS5AJER6NLRDGNYOI7FQODPWXXNNANCNFSM4CLZGSMQ .

ivanooi commented 5 years ago

Hi, I had managed to insert the author and title into Win XP. but I'm using Apache Imaging library....

Greenshot 2019-05-24 15 19 06

dragon66 commented 5 years ago

@ivanooi Can you send me the image to do a comparison?

ivanooi commented 5 years ago

Here is the photo. I can't see any different 😌

On Fri, 24 May 2019 at 17:55, dragon66 notifications@github.com wrote:

@ivanooi https://github.com/ivanooi Can you send me the image to do a comparison?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dragon66/icafe/issues/31?email_source=notifications&email_token=ADS5AJCBZGAWW3H225RBXK3PW63RJA5CNFSM4CLZGSM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWEYH7Q#issuecomment-495551486, or mute the thread https://github.com/notifications/unsubscribe-auth/ADS5AJGGGTEVSKBJJWZBOWDPW63RJANCNFSM4CLZGSMQ .

ivanooi commented 5 years ago

empty-out

dragon66 commented 5 years ago

@ivanooi Looks like Apache Imaging directly inserted those fields into Exif IFD instead of the Image IFD. However those are not standard Exif tags and I tried to view the information but they are not showing on my Windows 7 system.

One thing confuses me is that I looked at the image you sent before which contains the related metadata you inserted directly from Windows XP and found those fields were actually inserted into Image IFD but you mentioned they were showing well in Windows XP.

If your observation is right, I can't find a consistent explanation for this mystery.

I did do some hacking trying to confirm if put those information into Exif IFD will make them showing in Windows XP.

ivanooi commented 5 years ago

Hi, yea... you are right... showing nothing in Win10 as well but ok with XP.

On Sat, 25 May 2019 at 04:24, dragon66 notifications@github.com wrote:

@ivanooi https://github.com/ivanooi Looks like Apache Imaging directly inserted those fields into Exif IFD instead of the Image IFD. However those are not standard Exif tags and I tried to view the information but they are not showing on my Windows 7 system.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dragon66/icafe/issues/31?email_source=notifications&email_token=ADS5AJFKMMKC7EGWRD4ECHLPXBFHDA5CNFSM4CLZGSM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWGPOQI#issuecomment-495777601, or mute the thread https://github.com/notifications/unsubscribe-auth/ADS5AJFRASLWSJ3SFHA4VOTPXBFHDANCNFSM4CLZGSMQ .

ivanooi commented 5 years ago

@dragon66 Hi, tested the photo you gave me. Only Author appear in Win XP Greenshot 2019-05-25 08 31 14

dragon66 commented 5 years ago

@ivanooi That actually confirmed my guess. As for the tile is not showing, that is because the image also contains an empty Image Description which becomes the preferred title but it is empty.

Anyway, I did some changes to the code to actually include Windows related tags in ExifTag enum. Now you need to insert those windows related tags to both Image IFD and Exif IFD. This is the only way you can make it work for both Windows XP and later versions.

Check the latest changes of ICAFE and give it a try. Something like this:

exif.addImageField(TiffTag.WINDOWS_XP_AUTHOR, FieldType.WINDOWSXP, "Author");
exif.addExifField(ExifTag.WINDOWS_XP_AUTHOR, FieldType.WINDOWSXP, "Author");
ivanooi commented 5 years ago

great! I will give it a try

On Sat, 25 May 2019 at 09:56, dragon66 notifications@github.com wrote:

@ivanooi https://github.com/ivanooi That actually confirmed my guess. As for the tile is not showing, that is because the image also contains an empty Image Description which becomes the preferred title but it is empty.

Anyway, I did some changes to the code to actually include Windows related tags in ExifTag enum. Now you need to insert those windows related tags to both Image IFD and Exif IFD. This is the only way you can make it work for both Windows XP and later versions.

Check the latest changes of ICAFE and give it a try.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dragon66/icafe/issues/31?email_source=notifications&email_token=ADS5AJBG45GJ2EADDDY2GFTPXCMD5A5CNFSM4CLZGSM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWG3L5I#issuecomment-495826421, or mute the thread https://github.com/notifications/unsubscribe-auth/ADS5AJEU57ZRTRXOLVW7YHLPXCMD5ANCNFSM4CLZGSMQ .

ivanooi commented 5 years ago

Hi,

Title not working. Author ok now

I had tried the following way : 1) adding only this exif.addExifField( ExifTag.WINDOWS_XP_TITLE , FieldType.WINDOWSXP

2) adding this 2 exif.addImageField(TiffTag.WINDOWS_XP_TITLE , FieldType.WINDOWSXP exif.addExifField( ExifTag.WINDOWS_XP_TITLE , FieldType.WINDOWSXP

3) exif.addImageField(TiffTag.IMAGE_DESCRIPTION , FieldType.WINDOWSXP exif.addImageField(TiffTag.WINDOWS_XP_TITLE , FieldType.WINDOWSXP exif.addExifField( ExifTag.WINDOWS_XP_TITLE , FieldType.WINDOWSXP

4) exif.addImageField(TiffTag.WINDOWS_XP_TITLE , FieldType.WINDOWSXP exif.addExifField( ExifTag.WINDOWS_XP_TITLE , FieldType.WINDOWSXP

exif.addImageField(TiffTag.IMAGE_DESCRIPTION , FieldType.WINDOWSXP exif.addImageField(TiffTag.IMAGE_DESCRIPTION , FieldType.ASCII,

dragon66 commented 5 years ago

@ivanooi The second way should work. Try this one:

AuthorTitle

ivanooi commented 5 years ago

What had u done? I did try to spend some times looking at your code but can't find the problems at all Great! Finally it works! 👍

Greenshot 2019-05-25 22 47 12

ivanooi commented 5 years ago

source code not yet sync back, right? cant wait to try it. thanks again

dragon66 commented 5 years ago

@ivanooi It is in sync. I pushed the changes yesterday and used the same code to insert Title and Author in the image I provided before.

I am not sure how you inserted those fields but I just did a bit change of the code in TestMetadata.java to add the information to both places like this:

        // This method is for testing only
    private static Exif populateExif(Exif exif) throws IOException {
        exif.addImageField(TiffTag.WINDOWS_XP_AUTHOR, FieldType.WINDOWSXP, "Author");
            exif.addExifField(ExifTag.WINDOWS_XP_AUTHOR, FieldType.WINDOWSXP, "Author");
            exif.addImageField(TiffTag.WINDOWS_XP_TITLE, FieldType.WINDOWSXP, "Title");
            exif.addExifField(ExifTag.WINDOWS_XP_TITLE, FieldType.WINDOWSXP, "Title");

        return exif;
    }
        FileInputStream fin = new FileInputStream("myimage.jpg");
    FileOutputStream fout = new FileOutputStream("myimage-exif-inserted.jpg");

    Exif exif = new JpegExif();

    Metadata.insertExif(fin, fout, populateExif(exif), true);
ivanooi commented 5 years ago

I had found the problem,

exif.addImageField(TiffTag.IMAGE_DESCRIPTION cause the title disappear.

Thanks!

now... I need to find a way to balance WinXP and Mac as Mac depends on TiffTag.IMAGE_DESCRIPTION

dragon66 commented 5 years ago

@ivanooi I don't get why image description caused the title to disappear. As long as you also add that field, if Windows XP reads that field and takes it as it's preference, it should show it. Otherwise, as you have already inserted Windows XP specific tags and it should show those tags.

When it comes to mac, it will just grab image description and works as well.

Did you add title like this?

exif.addImageField(TiffTag.IMAGE_DESCRIPTION , FieldType.ASCII, "Title");
exif.addImageField(TiffTag.WINDOWS_XP_TITLE, FieldType.WINDOWSXP, "Title"); 
exif.addExifField(ExifTag.WINDOWS_XP_TITLE, FieldType.WINDOWSXP, "Title");
ivanooi commented 5 years ago

Yes, I did but it still causes WinXP title to disappear.

so, I share the WinXP subject field with title and subject data : exif.addExifField(ExifTag.WINDOWS_XP_SUBJECT , FieldType.WINDOWSXP, in XP subject field, you see some thing like this :
subject / title

for 7, vista and 10. no problem for title and subject fields. since they read the title and subject from TiffTag and not from ExifTag. so, it will not crash with WinXP subject field. u still see the title data in title field in 7, vista and 10.

and I leave image_description for Mac exif.addImageField(TiffTag.IMAGE_DESCRIPTION , FieldType.ASCII, so, sacrifice XP title and make the way for Mac. anyway, u still able to see the WinXP title data in the subject field in XP.

ya. bit funny but it works...