You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Kasper Føns <kf...@gmail.com> on 2012/03/06 23:46:34 UTC

[sanselan] Writing EXIF data to JPEG

Hi Sanselan.

I have a hard time finding out how to use Sanselan.

Suppose I have some JPEG picture which I want to add some attributes to.
If for example I want to add some user comment or date I try this:

TiffOutputSet outputSet = new TiffOutputSet();
TiffOutputField dateTaken = 
TiffOutputField.create(TiffConstants.EXIF_TAG_CREATE_DATE, 
outputSet.byteOrder, "2003:03:29 17:47:50");
TiffOutputField comment = 
TiffOutputField.create(TiffConstants.EXIF_TAG_IMAGE_DESCRIPTION, 
outputSet.byteOrder, "This is a test!");

However, both of these fails on "unexpected data type".
If I am not supposed to give a String, then what I am supposed to supply?

I hope you can help with these, probably noobish questions.

/Kasper

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


Re: [sanselan] Writing EXIF data to JPEG

Posted by Damjan Jovanovic <da...@apache.org>.
On Thu, Mar 8, 2012 at 7:02 PM, Kasper Føns <kf...@gmail.com> wrote:
>
>> Windows Explorer also likes the "XP" values (eg. EXIF_TAG_XPCOMMENT,
>> EXIF_TAG_XPAUTHOR), maybe try writing those as well?
>
> Hmm. You seem to be right that explorer likes the XP values. However, I
> can't figure out how to write to them. I can see that they are BYTE values,
> but how to convert a string into the wanted bytes?
>
> This is the result I get:
> ---- IFD0 ----
> XP Comment                      : 態灳牥潃浭湥t
> XP Author                       : 態灳牥畁桴牯
>
> With this code:
> byte[] bytesComment =
> ExifTagConstants.EXIF_TAG_XPCOMMENT.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII,
> "KasperComment", set.byteOrder);
> byte[] bytesAuthor =
> ExifTagConstants.EXIF_TAG_XPAUTHOR.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII,
> "KasperAuthor", set.byteOrder);
> TiffOutputField commentField = new
> TiffOutputField(ExifTagConstants.EXIF_TAG_XPCOMMENT,
> ExifTagConstants.EXIF_TAG_XPCOMMENT.dataTypes[0], bytesComment.length,
> bytesComment);
> TiffOutputField authorField = new
> TiffOutputField(ExifTagConstants.EXIF_TAG_XPAUTHOR,
> ExifTagConstants.EXIF_TAG_XPAUTHOR.dataTypes[0], bytesAuthor.length,
> bytesAuthor);
> set.getOrCreateRootDirectory().add(commentField);
> set.getOrCreateRootDirectory().add(authorField);
>
>
> /Kasper

There's no easy way in Sanselan 0.97: the XP fields use little-endian
UTF-16 (no matter what the byte ordering of the file is, thanks
Microsoft you useless @*#%!) so try this:

byte[] rawBytes = "KasperAuthor".getBytes("UTF-16LE");
byte[] nullTerminatedBytes = new byte[rawBytes.length + 2];
TiffOutputField authorField = new
  TiffOutputField(ExifTagConstants.EXIF_TAG_XPAUTHOR,
  ExifTagConstants.EXIF_TAG_XPAUTHOR.dataTypes[0], nullTerminatedBytes.length,
  nullTerminatedBytes);

Damjan

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


Re: [sanselan] Writing EXIF data to JPEG

Posted by Kasper Føns <kf...@gmail.com>.
> Windows Explorer also likes the "XP" values (eg. EXIF_TAG_XPCOMMENT,
> EXIF_TAG_XPAUTHOR), maybe try writing those as well?
Hmm. You seem to be right that explorer likes the XP values. However, I 
can't figure out how to write to them. I can see that they are BYTE 
values, but how to convert a string into the wanted bytes?

This is the result I get:
---- IFD0 ----
XP Comment                      : 態灳牥潃浭湥t
XP Author                       : 態灳牥畁桴牯

With this code:
byte[] bytesComment = 
ExifTagConstants.EXIF_TAG_XPCOMMENT.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII, 
"KasperComment", set.byteOrder);
byte[] bytesAuthor = 
ExifTagConstants.EXIF_TAG_XPAUTHOR.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII, 
"KasperAuthor", set.byteOrder);
TiffOutputField commentField = new 
TiffOutputField(ExifTagConstants.EXIF_TAG_XPCOMMENT, 
ExifTagConstants.EXIF_TAG_XPCOMMENT.dataTypes[0], bytesComment.length, 
bytesComment);
TiffOutputField authorField = new 
TiffOutputField(ExifTagConstants.EXIF_TAG_XPAUTHOR, 
ExifTagConstants.EXIF_TAG_XPAUTHOR.dataTypes[0], bytesAuthor.length, 
bytesAuthor);
set.getOrCreateRootDirectory().add(commentField);
set.getOrCreateRootDirectory().add(authorField);

/Kasper

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


RE: [sanselan] Writing EXIF data to JPEG

Posted by tiersene <ti...@gmail.com>.
Hi mgainty


EXIF_TAG_XPCOMMENT is a final constant which cannot be modified> 

Thank you for the info

What about EXIF_TAG_USER_COMMENT?





--
View this message in context: http://apache-commons.680414.n4.nabble.com/sanselan-Writing-EXIF-data-to-JPEG-tp4451598p4637453.html
Sent from the Commons - User mailing list archive at Nabble.com.

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


RE: [sanselan] Writing EXIF data to JPEG

Posted by Martin Gainty <mg...@hotmail.com>.
EXIF_TAG_XPCOMMENT is a final constant which cannot be modified

package org.apache.commons.imaging.formats.tiff.constants;
public interface MicrosoftTagConstants {
    public static final TagInfoXpString EXIF_TAG_XPCOMMENT = new TagInfoXpString(
            "XPComment", 0x9c9c, -1,
            TiffDirectoryType.EXIF_DIRECTORY_IFD0);

does this not conform to your understanding..
Martin 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.


> Date: Tue, 31 Jul 2012 16:45:35 -0700
> From: tiersene@gmail.com
> To: user@commons.apache.org
> Subject: Re: [sanselan] Writing EXIF data to JPEG
> 
> Hi
> 
> @Kasper did you get things working??
> 
> I'm trying to write an android application that lets me read and write user
> comments in JPEG files.
> I'm using sanselan since there is no user comments field in the Android
> ExifInterface API. The issue is that the USER_COMMENT and the XPCOMMENT
> remain unchanged.
> 
> Here is part of my code
> 
> IImageMetadata meta = null;
> meta = Sanselan.getMetadata(jpegImageFile);
> JpegImageMetadata jpegMetadata = (JpegImageMetadata) meta;
> TiffOutputSet set = new
> TiffOutputSet(TiffConstants.BYTE_ORDER_LITTLE_ENDIAN);
>     	
> byte[] bytesXPComment =
>     
> ExifTagConstants.EXIF_TAG_XPCOMMENT.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII,
>     			"My xp comments", set.byteOrder);
> TiffOutputField xpcommentField = new
>     			TiffOutputField(ExifTagConstants.EXIF_TAG_XPCOMMENT,
>     			ExifTagConstants.EXIF_TAG_XPCOMMENT.dataTypes[0],
> bytesXPComment.length,
>     			bytesXPComment);
> set.getOrCreateRootDirectory().add(xpcommentField);
>     		
> byte[] bytesUserComment =
>    
> ExifTagConstants.EXIF_TAG_USER_COMMENT.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII,
>     			"My user comments", set.byteOrder);
> TiffOutputField usercommentField = new
>     			TiffOutputField(ExifTagConstants.EXIF_TAG_USER_COMMENT,
>     			ExifTagConstants.EXIF_TAG_USER_COMMENT.dataTypes[0],
> bytesUserComment.length,
>     			bytesUserComment);
> set.getOrCreateRootDirectory().add(usercommentField);
> 
> Thanking you in advance. 
> 
> 
> 
> --
> View this message in context: http://apache-commons.680414.n4.nabble.com/sanselan-Writing-EXIF-data-to-JPEG-tp4451598p4637450.html
> Sent from the Commons - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 
 		 	   		  

Re: [sanselan] Writing EXIF data to JPEG

Posted by tiersene <ti...@gmail.com>.
Hi

@Kasper did you get things working??

I'm trying to write an android application that lets me read and write user
comments in JPEG files.
I'm using sanselan since there is no user comments field in the Android
ExifInterface API. The issue is that the USER_COMMENT and the XPCOMMENT
remain unchanged.

Here is part of my code

IImageMetadata meta = null;
meta = Sanselan.getMetadata(jpegImageFile);
JpegImageMetadata jpegMetadata = (JpegImageMetadata) meta;
TiffOutputSet set = new
TiffOutputSet(TiffConstants.BYTE_ORDER_LITTLE_ENDIAN);
    	
byte[] bytesXPComment =
    
ExifTagConstants.EXIF_TAG_XPCOMMENT.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII,
    			"My xp comments", set.byteOrder);
TiffOutputField xpcommentField = new
    			TiffOutputField(ExifTagConstants.EXIF_TAG_XPCOMMENT,
    			ExifTagConstants.EXIF_TAG_XPCOMMENT.dataTypes[0],
bytesXPComment.length,
    			bytesXPComment);
set.getOrCreateRootDirectory().add(xpcommentField);
    		
byte[] bytesUserComment =
   
ExifTagConstants.EXIF_TAG_USER_COMMENT.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII,
    			"My user comments", set.byteOrder);
TiffOutputField usercommentField = new
    			TiffOutputField(ExifTagConstants.EXIF_TAG_USER_COMMENT,
    			ExifTagConstants.EXIF_TAG_USER_COMMENT.dataTypes[0],
bytesUserComment.length,
    			bytesUserComment);
set.getOrCreateRootDirectory().add(usercommentField);

Thanking you in advance. 



--
View this message in context: http://apache-commons.680414.n4.nabble.com/sanselan-Writing-EXIF-data-to-JPEG-tp4451598p4637450.html
Sent from the Commons - User mailing list archive at Nabble.com.

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


Re: [sanselan] Writing EXIF data to JPEG

Posted by Kasper Føns <kf...@gmail.com>.
> We can safely conclude from this that there is many reasons why 1.0
> needs to be released, and 0.97 needs to die :).
I can agree to that.

Now that you have helped me so immensely, I will try to repay you a 
little with some feedback on the project.

I will be biased by the 0.97 version and the fact that all I wanted to 
do was to write some MetaData into a JPEG image on Android.

== Tag creation ==
- Creating a tag at 0.97 is surprisingly difficult.
   - There is no javadoc on any of the tags
   - There is no clear-to-use examples (that I found)
   - Supplying a String to TiffOutputField.create(...) blows up, even on 
a Ascii type tag. (I know the SVN version fixes some of this)
   - Wanting to create the EXIF_TAG_CREATE_DATE, I need to create this 
from a String, however, there should be a method taking a java.util.Date 
class and formatting it correctly. This also applies to getting the date.
   - EXIF_TAG_XP* tags should automatically use the UTF18LE encoding on 
a String.
   - It would be nice to have a simply-to-use api on the OutputSet. For 
example outputset.setTag(EXIF_TAG_CREATE_DATE, new Date()).

== Android support ==
I haven't actually used Sanselan directly, since I needed it to work on 
Android. Instead I used http://code.google.com/p/sanselanandroid/. This 
project is using version 0.97.
It would be nice to have native Android support from Sanselan. I have 
seen several stackoverflow posts about using Sanselan on Android.
Android does not support java.awt.*, so if the functionality used from 
there could be dropped, Android seems to be fully supported.

== Website ==
  - The website contains many dead links.
  - There should be more examples or help.

== Generics ==
I know the project targeted Java 1.4, "Sanselan only requires Java 1.4 
or later.", however I feel like generics would be a great upgrade.
For example, when seeing an ArrayList in the project, you really have no 
idea what it contains unless there is some javadoc that tells you so.

Hope this is useful. If I had the time, I would like to help. However, I 
am swamped at the moment.
I want to say thank you once again. Thank you!

/Kasper

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


Re: [sanselan] Writing EXIF data to JPEG

Posted by Damjan Jovanovic <da...@gmail.com>.
On Thu, Mar 8, 2012 at 6:39 PM, Kasper Føns <kf...@gmail.com> wrote:
>
>> I wouldn't count on Windows Explorer to give you the right values.
>> Rather check it against exiftool
>> (www.sno.phy.queensu.ca/~phil/exiftool/):
>> exiftool -a -g1 -u image.tiff
>>
>> Windows Explorer also likes the "XP" values (eg. EXIF_TAG_XPCOMMENT,
>> EXIF_TAG_XPAUTHOR), maybe try writing those as well?
>>
>> Damjan
>>
> Sorry for asking so many questions :( I hope it is okay.

Yes it's okay :).

> Hmm. It does not seem like the XP values work. They do not show correctly.
>
> Anyways, I tried using the code I sent you without special characters:
> byte[] bytesComment =
> ExifTagConstants.EXIF_TAG_USER_COMMENT.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII,
> "KasperComment", set.byteOrder);
> byte[] bytesAuthor =
> TiffTagConstants.TIFF_TAG_ARTIST.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII,
> "KasperAuthor", set.byteOrder);
>
> TiffOutputField commentField = new
> TiffOutputField(ExifTagConstants.EXIF_TAG_USER_COMMENT,
> ExifTagConstants.EXIF_TAG_USER_COMMENT.dataTypes[0], bytesComment.length,
> bytesComment);
> TiffOutputField authorField = new
> TiffOutputField(TiffTagConstants.TIFF_TAG_ARTIST,
> TiffTagConstants.TIFF_TAG_ARTIST.dataTypes[0], bytesAuthor.length,
> bytesAuthor);
> set.getOrCreateExifDirectory().add(commentField);
> set.getOrCreateRootDirectory().add(authorField);
>
> Then the exif tools shows (and so do windows explorer):
> ---- IFD0 ----
> Artist                          : KasperAuthor
> ---- ExifIFD ----
> User Comment                    : KasperComment
> ---- JFIF ----
> JFIF Version                    : 1.01
>
> However, trying the same, but adding an å to KasperComment and KasperAuthor
> gives the following:
> ---- IFD0 ----
> Artist                          : KasperAuthorå
> ---- ExifIFD ----
> User Comment                    : 䭡獰敲䍯浭敮瓃
> ---- JFIF ----
> JFIF Version                    : 1.01
>
> It seems the UserComment has been destroyed. Now it is suddenly chinese
> characters!?
> Windows explorer shows the artist but not the usercomment.
>
> Is this something to do with ExifDirectory vs RootDirectory?

No, the directory wouldn't affect the output.

Sanselan 0.97:
* doesn't null-terminate ASCII strings (eg. Artist), so you have to
allocate a byte array one element bigger and copy the encoded bytes to
it.
* uses the system locale for ASCII encoding, which is UTF-16LE on
Windows, even though TIFF requires UTF-8

So for ASCII fields instead of using encodeValue(), use
getBytes("UTF-8") and copy to a byte array with one more element (so
that the last element is null) like I showed you in the previous
email.

For UserComment what Sanselan does is autodetect the encoding: this
will work for ASCII and write ASCII, but in 0.97 it wrongly assumed
that the unicode encoding is UTF-8, whereas it's actually UTF-16 with
byte ordering depending on the file's byte ordering. So in 0.97 you
have to encode this manually yourself using a big hack:

byte[] unicodeMarker = new byte[]{ 0x55, 0x4E, 0x49, 0x43, 0x4F, 0x44,
0x45, 0x00 };
byte[] comment = "My Comment".getBytes("UTF-16LE"); // OR UTF-16BE if
the file is big-endian!
byte[] bytesComment = new byte[unicodeMarker.length + comment.length];
System.arraycopy(marker, 0, bytesComment, 0, marker.length);
System.arraycopy(comment, 0, bytesComment, marker.length, comment.length);
TiffOutputField commentField = new
  TiffOutputField(ExifTagConstants.EXIF_TAG_USER_COMMENT,
  ExifTagConstants.EXIF_TAG_USER_COMMENT.dataTypes[0], bytesComment.length,
  bytesComment);


We can safely conclude from this that there is many reasons why 1.0
needs to be released, and 0.97 needs to die :).

>
> /Kasper
>

Damjan

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


Re: [sanselan] Writing EXIF data to JPEG

Posted by Kasper Føns <kf...@gmail.com>.
> I wouldn't count on Windows Explorer to give you the right values.
> Rather check it against exiftool
> (www.sno.phy.queensu.ca/~phil/exiftool/):
> exiftool -a -g1 -u image.tiff
>
> Windows Explorer also likes the "XP" values (eg. EXIF_TAG_XPCOMMENT,
> EXIF_TAG_XPAUTHOR), maybe try writing those as well?
>
> Damjan
>
Sorry for asking so many questions :( I hope it is okay.

Hmm. It does not seem like the XP values work. They do not show correctly.

Anyways, I tried using the code I sent you without special characters:
byte[] bytesComment = 
ExifTagConstants.EXIF_TAG_USER_COMMENT.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII, 
"KasperComment", set.byteOrder);
byte[] bytesAuthor = 
TiffTagConstants.TIFF_TAG_ARTIST.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII, 
"KasperAuthor", set.byteOrder);
TiffOutputField commentField = new 
TiffOutputField(ExifTagConstants.EXIF_TAG_USER_COMMENT, 
ExifTagConstants.EXIF_TAG_USER_COMMENT.dataTypes[0], 
bytesComment.length, bytesComment);
TiffOutputField authorField = new 
TiffOutputField(TiffTagConstants.TIFF_TAG_ARTIST, 
TiffTagConstants.TIFF_TAG_ARTIST.dataTypes[0], bytesAuthor.length, 
bytesAuthor);
set.getOrCreateExifDirectory().add(commentField);
set.getOrCreateRootDirectory().add(authorField);

Then the exif tools shows (and so do windows explorer):
---- IFD0 ----
Artist                          : KasperAuthor
---- ExifIFD ----
User Comment                    : KasperComment
---- JFIF ----
JFIF Version                    : 1.01

However, trying the same, but adding an å to KasperComment and 
KasperAuthor gives the following:
---- IFD0 ----
Artist                          : KasperAuthorå
---- ExifIFD ----
User Comment                    : 䭡獰敲䍯浭敮瓃
---- JFIF ----
JFIF Version                    : 1.01

It seems the UserComment has been destroyed. Now it is suddenly chinese 
characters!?
Windows explorer shows the artist but not the usercomment.

Is this something to do with ExifDirectory vs RootDirectory?

/Kasper

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


Re: [sanselan] Writing EXIF data to JPEG

Posted by Damjan Jovanovic <da...@apache.org>.
On Thu, Mar 8, 2012 at 2:45 PM, Kasper Føns <kf...@gmail.com> wrote:
>
>> Sorry about the website, I plan on fixing it with the 1.0 release.
>>
>> UserComment is one of the uglier cases, as it uses that GPS string
>> type with a special prefix to distinguish character encodings.
>>
>> Try using TagInfo.Text's encodeValue() method to convert the String to
>> byte[], then pass that to
>> new TiffOutputField(ExifTagConstants.EXIF_TAG_USER_COMMENT,
>>                    ExifTagConstants.EXIF_TAG_USER_COMMENT.fieldTypes,
>> bytes.length, bytes);
>
> Thanks for the help, I can now save a usercomment and the artist field
> successfully.
>
> There is just one tiny little problem that I am now requesting some help
> for.
> I am able to put international characters into the artist and usercomment
> field, however, the usercomment field is not shown in Windows Explorer, but
> the artist is.
> I have been searching the internet and found that the byteorder should be
> little_endian, but that was the default case.
> Is there some way to put in internation characters in the usercomment field?
>
> Here is my current code. I altered yours a bit:
>
> TiffOutputSet set = new
> TiffOutputSet(TiffConstants.BYTE_ORDER_LITTLE_ENDIAN);
>
> byte[] bytesComment =
> ExifTagConstants.EXIF_TAG_USER_COMMENT.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII,
> "KasperCommentĹ", set.byteOrder);
> byte[] bytesAuthor =
> TiffTagConstants.TIFF_TAG_ARTIST.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII,
> "KasperAuthorĹ", set.byteOrder);
> TiffOutputField commentField = new
> TiffOutputField(ExifTagConstants.EXIF_TAG_USER_COMMENT,
> ExifTagConstants.EXIF_TAG_USER_COMMENT.dataTypes[0], bytesComment.length,
> bytesComment);
> TiffOutputField authorField = new
> TiffOutputField(TiffTagConstants.TIFF_TAG_ARTIST,
> TiffTagConstants.TIFF_TAG_ARTIST.dataTypes[0], bytesAuthor.length,
> bytesAuthor);
> set.getOrCreateExifDirectory().add(commentField);
> set.getOrCreateRootDirectory().add(authorField);
>
> Thanks on beforehand, and thanks for the help so far!
>
>
> /Kasper

I wouldn't count on Windows Explorer to give you the right values.
Rather check it against exiftool
(www.sno.phy.queensu.ca/~phil/exiftool/):
exiftool -a -g1 -u image.tiff

Windows Explorer also likes the "XP" values (eg. EXIF_TAG_XPCOMMENT,
EXIF_TAG_XPAUTHOR), maybe try writing those as well?

Damjan

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


Re: [sanselan] Writing EXIF data to JPEG

Posted by Kasper Føns <kf...@gmail.com>.
> Sorry about the website, I plan on fixing it with the 1.0 release.
>
> UserComment is one of the uglier cases, as it uses that GPS string
> type with a special prefix to distinguish character encodings.
>
> Try using TagInfo.Text's encodeValue() method to convert the String to
> byte[], then pass that to
> new TiffOutputField(ExifTagConstants.EXIF_TAG_USER_COMMENT,
> 	            ExifTagConstants.EXIF_TAG_USER_COMMENT.fieldTypes,
> bytes.length, bytes);
Thanks for the help, I can now save a usercomment and the artist field 
successfully.

There is just one tiny little problem that I am now requesting some help 
for.
I am able to put international characters into the artist and 
usercomment field, however, the usercomment field is not shown in 
Windows Explorer, but the artist is.
I have been searching the internet and found that the byteorder should 
be little_endian, but that was the default case.
Is there some way to put in internation characters in the usercomment field?

Here is my current code. I altered yours a bit:

TiffOutputSet set = new 
TiffOutputSet(TiffConstants.BYTE_ORDER_LITTLE_ENDIAN);

byte[] bytesComment = 
ExifTagConstants.EXIF_TAG_USER_COMMENT.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII, 
"KasperCommentÅ", set.byteOrder);
byte[] bytesAuthor = 
TiffTagConstants.TIFF_TAG_ARTIST.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII, 
"KasperAuthorÅ", set.byteOrder);
TiffOutputField commentField = new 
TiffOutputField(ExifTagConstants.EXIF_TAG_USER_COMMENT, 
ExifTagConstants.EXIF_TAG_USER_COMMENT.dataTypes[0], 
bytesComment.length, bytesComment);
TiffOutputField authorField = new 
TiffOutputField(TiffTagConstants.TIFF_TAG_ARTIST, 
TiffTagConstants.TIFF_TAG_ARTIST.dataTypes[0], bytesAuthor.length, 
bytesAuthor);
set.getOrCreateExifDirectory().add(commentField);
set.getOrCreateRootDirectory().add(authorField);

Thanks on beforehand, and thanks for the help so far!

/Kasper

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


Re: [sanselan] Writing EXIF data to JPEG

Posted by Damjan Jovanovic <da...@gmail.com>.
On Wed, Mar 7, 2012 at 10:37 PM, Kasper Føns <kf...@gmail.com> wrote:
> On 07-03-2012 19:41, Damjan Jovanovic wrote:
>>
>> On Wed, Mar 7, 2012 at 8:07 PM, Kasper Føns<kf...@gmail.com>  wrote:
>>>
>>> On 07-03-2012 06:37, Damjan Jovanovic wrote:
>>>>
>>>> On Wed, Mar 7, 2012 at 12:46 AM, Kasper Føns<kf...@gmail.com>    wrote:
>>>>>
>>>>> Hi Sanselan.
>>>>>
>>>>> I have a hard time finding out how to use Sanselan.
>>>>>
>>>>> Suppose I have some JPEG picture which I want to add some attributes
>>>>> to.
>>>>> If for example I want to add some user comment or date I try this:
>>>>>
>>>>> TiffOutputSet outputSet = new TiffOutputSet();
>>>>> TiffOutputField dateTaken =
>>>>> TiffOutputField.create(TiffConstants.EXIF_TAG_CREATE_DATE,
>>>>> outputSet.byteOrder, "2003:03:29 17:47:50");
>>>>> TiffOutputField comment =
>>>>> TiffOutputField.create(TiffConstants.EXIF_TAG_IMAGE_DESCRIPTION,
>>>>> outputSet.byteOrder, "This is a test!");
>>>>>
>>>>> However, both of these fails on "unexpected data type".
>>>>> If I am not supposed to give a String, then what I am supposed to
>>>>> supply?
>>>>>
>>>>> I hope you can help with these, probably noobish questions.
>>>>>
>>>>> /Kasper
>>>>
>>>> That TiffOutputField.create() was a horribly broken API that I've
>>>> eliminated in the latest SVN, and replaced with a new, beautiful, type
>>>> safe, code completable, byte order independent
>>>> TiffOutputDirectory.add() API.
>>>>
>>>> I recommend you use the latest SVN, or wait for the 1.0 release in a
>>>> few weeks. If you really must use version 0.97, I think the only way
>>>> to get strings to work is to convert the string to bytes with
>>>> getBytes(), null-terminate those yourself, then pass them to the
>>>> low-level constructor "new TiffOutputField(...)".
>>>>
>>>> Damjan
>>>
>>>
>>> Hi again Damjan.
>>>
>>> Thanks for the response. I have had a look at the new API, and it looks
>>> cleaner.
>>>
>>> I want to run this on Android, and I can see that there is a heavy
>>> dependency on java.awt, which unfortunately is not in Android.
>>> Do you have some hints as what to do?
>>>
>>>
>>> /Kasper
>>
>> No, sorry, Android isn't supported at the moment. There is a fork
>> (http://code.google.com/p/sanselanandroid/) which supposedly lets you
>> do EXIF on Android, but I've never tried it.
>>
>> Damjan
>>
> Hi again again.
>
> So, the android port is using 0.97 unfortunately, so I can't make use of
> your nice API.
> Is it possible that you could show me with an example, how I would write the
> tag "UserComment" using 0.97? Do you have some samples I can look at?
> Also, the website seems to contain a lot of dead links.
>
>
> /Kasper

Sorry about the website, I plan on fixing it with the 1.0 release.

UserComment is one of the uglier cases, as it uses that GPS string
type with a special prefix to distinguish character encodings.

Try using TagInfo.Text's encodeValue() method to convert the String to
byte[], then pass that to
new TiffOutputField(ExifTagConstants.EXIF_TAG_USER_COMMENT,
	            ExifTagConstants.EXIF_TAG_USER_COMMENT.fieldTypes,
bytes.length, bytes);

Good luck
Damjan

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


Re: [sanselan] Writing EXIF data to JPEG

Posted by Kasper Føns <kf...@gmail.com>.
On 07-03-2012 19:41, Damjan Jovanovic wrote:
> On Wed, Mar 7, 2012 at 8:07 PM, Kasper Føns<kf...@gmail.com>  wrote:
>> On 07-03-2012 06:37, Damjan Jovanovic wrote:
>>> On Wed, Mar 7, 2012 at 12:46 AM, Kasper Føns<kf...@gmail.com>    wrote:
>>>> Hi Sanselan.
>>>>
>>>> I have a hard time finding out how to use Sanselan.
>>>>
>>>> Suppose I have some JPEG picture which I want to add some attributes to.
>>>> If for example I want to add some user comment or date I try this:
>>>>
>>>> TiffOutputSet outputSet = new TiffOutputSet();
>>>> TiffOutputField dateTaken =
>>>> TiffOutputField.create(TiffConstants.EXIF_TAG_CREATE_DATE,
>>>> outputSet.byteOrder, "2003:03:29 17:47:50");
>>>> TiffOutputField comment =
>>>> TiffOutputField.create(TiffConstants.EXIF_TAG_IMAGE_DESCRIPTION,
>>>> outputSet.byteOrder, "This is a test!");
>>>>
>>>> However, both of these fails on "unexpected data type".
>>>> If I am not supposed to give a String, then what I am supposed to supply?
>>>>
>>>> I hope you can help with these, probably noobish questions.
>>>>
>>>> /Kasper
>>> That TiffOutputField.create() was a horribly broken API that I've
>>> eliminated in the latest SVN, and replaced with a new, beautiful, type
>>> safe, code completable, byte order independent
>>> TiffOutputDirectory.add() API.
>>>
>>> I recommend you use the latest SVN, or wait for the 1.0 release in a
>>> few weeks. If you really must use version 0.97, I think the only way
>>> to get strings to work is to convert the string to bytes with
>>> getBytes(), null-terminate those yourself, then pass them to the
>>> low-level constructor "new TiffOutputField(...)".
>>>
>>> Damjan
>>
>> Hi again Damjan.
>>
>> Thanks for the response. I have had a look at the new API, and it looks
>> cleaner.
>>
>> I want to run this on Android, and I can see that there is a heavy
>> dependency on java.awt, which unfortunately is not in Android.
>> Do you have some hints as what to do?
>>
>>
>> /Kasper
> No, sorry, Android isn't supported at the moment. There is a fork
> (http://code.google.com/p/sanselanandroid/) which supposedly lets you
> do EXIF on Android, but I've never tried it.
>
> Damjan
>
Hi again again.

So, the android port is using 0.97 unfortunately, so I can't make use of 
your nice API.
Is it possible that you could show me with an example, how I would write 
the tag "UserComment" using 0.97? Do you have some samples I can look at?
Also, the website seems to contain a lot of dead links.

/Kasper

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


Re: [sanselan] Writing EXIF data to JPEG

Posted by Damjan Jovanovic <da...@apache.org>.
On Wed, Mar 7, 2012 at 8:07 PM, Kasper Føns <kf...@gmail.com> wrote:
> On 07-03-2012 06:37, Damjan Jovanovic wrote:
>>
>> On Wed, Mar 7, 2012 at 12:46 AM, Kasper Føns<kf...@gmail.com>  wrote:
>>>
>>> Hi Sanselan.
>>>
>>> I have a hard time finding out how to use Sanselan.
>>>
>>> Suppose I have some JPEG picture which I want to add some attributes to.
>>> If for example I want to add some user comment or date I try this:
>>>
>>> TiffOutputSet outputSet = new TiffOutputSet();
>>> TiffOutputField dateTaken =
>>> TiffOutputField.create(TiffConstants.EXIF_TAG_CREATE_DATE,
>>> outputSet.byteOrder, "2003:03:29 17:47:50");
>>> TiffOutputField comment =
>>> TiffOutputField.create(TiffConstants.EXIF_TAG_IMAGE_DESCRIPTION,
>>> outputSet.byteOrder, "This is a test!");
>>>
>>> However, both of these fails on "unexpected data type".
>>> If I am not supposed to give a String, then what I am supposed to supply?
>>>
>>> I hope you can help with these, probably noobish questions.
>>>
>>> /Kasper
>>
>> That TiffOutputField.create() was a horribly broken API that I've
>> eliminated in the latest SVN, and replaced with a new, beautiful, type
>> safe, code completable, byte order independent
>> TiffOutputDirectory.add() API.
>>
>> I recommend you use the latest SVN, or wait for the 1.0 release in a
>> few weeks. If you really must use version 0.97, I think the only way
>> to get strings to work is to convert the string to bytes with
>> getBytes(), null-terminate those yourself, then pass them to the
>> low-level constructor "new TiffOutputField(...)".
>>
>> Damjan
>
>
> Hi again Damjan.
>
> Thanks for the response. I have had a look at the new API, and it looks
> cleaner.
>
> I want to run this on Android, and I can see that there is a heavy
> dependency on java.awt, which unfortunately is not in Android.
> Do you have some hints as what to do?
>
>
> /Kasper

No, sorry, Android isn't supported at the moment. There is a fork
(http://code.google.com/p/sanselanandroid/) which supposedly lets you
do EXIF on Android, but I've never tried it.

Damjan

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


Re: [sanselan] Writing EXIF data to JPEG

Posted by Kasper Føns <kf...@gmail.com>.
On 07-03-2012 06:37, Damjan Jovanovic wrote:
> On Wed, Mar 7, 2012 at 12:46 AM, Kasper Føns<kf...@gmail.com>  wrote:
>> Hi Sanselan.
>>
>> I have a hard time finding out how to use Sanselan.
>>
>> Suppose I have some JPEG picture which I want to add some attributes to.
>> If for example I want to add some user comment or date I try this:
>>
>> TiffOutputSet outputSet = new TiffOutputSet();
>> TiffOutputField dateTaken =
>> TiffOutputField.create(TiffConstants.EXIF_TAG_CREATE_DATE,
>> outputSet.byteOrder, "2003:03:29 17:47:50");
>> TiffOutputField comment =
>> TiffOutputField.create(TiffConstants.EXIF_TAG_IMAGE_DESCRIPTION,
>> outputSet.byteOrder, "This is a test!");
>>
>> However, both of these fails on "unexpected data type".
>> If I am not supposed to give a String, then what I am supposed to supply?
>>
>> I hope you can help with these, probably noobish questions.
>>
>> /Kasper
> That TiffOutputField.create() was a horribly broken API that I've
> eliminated in the latest SVN, and replaced with a new, beautiful, type
> safe, code completable, byte order independent
> TiffOutputDirectory.add() API.
>
> I recommend you use the latest SVN, or wait for the 1.0 release in a
> few weeks. If you really must use version 0.97, I think the only way
> to get strings to work is to convert the string to bytes with
> getBytes(), null-terminate those yourself, then pass them to the
> low-level constructor "new TiffOutputField(...)".
>
> Damjan

Hi again Damjan.

Thanks for the response. I have had a look at the new API, and it looks 
cleaner.

I want to run this on Android, and I can see that there is a heavy 
dependency on java.awt, which unfortunately is not in Android.
Do you have some hints as what to do?

/Kasper


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


Re: [sanselan] Writing EXIF data to JPEG

Posted by Damjan Jovanovic <da...@apache.org>.
On Wed, Mar 7, 2012 at 12:46 AM, Kasper Føns <kf...@gmail.com> wrote:
> Hi Sanselan.
>
> I have a hard time finding out how to use Sanselan.
>
> Suppose I have some JPEG picture which I want to add some attributes to.
> If for example I want to add some user comment or date I try this:
>
> TiffOutputSet outputSet = new TiffOutputSet();
> TiffOutputField dateTaken =
> TiffOutputField.create(TiffConstants.EXIF_TAG_CREATE_DATE,
> outputSet.byteOrder, "2003:03:29 17:47:50");
> TiffOutputField comment =
> TiffOutputField.create(TiffConstants.EXIF_TAG_IMAGE_DESCRIPTION,
> outputSet.byteOrder, "This is a test!");
>
> However, both of these fails on "unexpected data type".
> If I am not supposed to give a String, then what I am supposed to supply?
>
> I hope you can help with these, probably noobish questions.
>
> /Kasper

That TiffOutputField.create() was a horribly broken API that I've
eliminated in the latest SVN, and replaced with a new, beautiful, type
safe, code completable, byte order independent
TiffOutputDirectory.add() API.

I recommend you use the latest SVN, or wait for the 1.0 release in a
few weeks. If you really must use version 0.97, I think the only way
to get strings to work is to convert the string to bytes with
getBytes(), null-terminate those yourself, then pass them to the
low-level constructor "new TiffOutputField(...)".

Damjan

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