Re: [sanselan] Writing EXIF data to JPEG

2012-03-09 Thread Kasper Føns



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-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



Re: [sanselan] Writing EXIF data to JPEG

2012-03-08 Thread Kasper Føns



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-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



Re: [sanselan] Writing EXIF data to JPEG

2012-03-08 Thread Kasper Føns



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-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



Re: [sanselan] Writing EXIF data to JPEG

2012-03-08 Thread Kasper Føns



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-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



Re: [sanselan] Writing EXIF data to JPEG

2012-03-07 Thread Kasper Føns

On 07-03-2012 06:37, Damjan Jovanovic wrote:

On Wed, Mar 7, 2012 at 12:46 AM, Kasper Fønskfo...@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-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



Re: [sanselan] Writing EXIF data to JPEG

2012-03-07 Thread Kasper Føns

On 07-03-2012 19:41, Damjan Jovanovic wrote:

On Wed, Mar 7, 2012 at 8:07 PM, Kasper Fønskfo...@gmail.com  wrote:

On 07-03-2012 06:37, Damjan Jovanovic wrote:

On Wed, Mar 7, 2012 at 12:46 AM, Kasper Fønskfo...@gmail.comwrote:

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-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



[sanselan] Writing EXIF data to JPEG

2012-03-06 Thread Kasper Føns

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-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org