Re: Creating EXIF tags (TiffOutputField) the right way

2016-05-28 Thread Joakim Knudsen
Hi Benedikt, and thanks for replying!

So, if FieldType is unused, maybe the alternative, simpler constructor is
more appropriate/correct to use?

// try using the approach given in the example (modified from the GPS tag):
TiffOutputField exif_comment = TiffOutputField.create(
TiffConstants.EXIF_TAG_USER_COMMENT,
outputSet.byteOrder, textToSet);

However, now Sanselan throws an ImageWriteException:
org.apache.sanselan.ImageWriteException: Tag has unexpected data type.

So are you 100% sure field type should not be set (to ASCII)?

Next, you're saying the string to set (textToSet) is converted internally
to byte array, using US-ASCII encoding.
If I try writing "æøåæøå" to a file, I get "쎦쎸쎥쎦쎸쎥" when I copy the JPEG
out and check Properties in Windows Explorer.
If I write only ASCII characters, e.g. "Test", then that comes through just
fine.

In summary, here is the code that works for me (except non-ASCII
characters):


*//
http://mail-archives.apache.org/mod_mbox/commons-user/201203.mbox/%3CCAJm2B-mYCXYKuyu=Hs8UAZCpw-B=kwuz4gszfuobvzwun0l...@mail.gmail.com%3E
<http://mail-archives.apache.org/mod_mbox/commons-user/201203.mbox/%3CCAJm2B-mYCXYKuyu=Hs8UAZCpw-B=kwuz4gszfuobvzwun0l...@mail.gmail.com%3E>*byte
b[] = ExifTagConstants.EXIF_TAG_USER_COMMENT.encodeValue(
TiffFieldTypeConstants.FIELD_TYPE_ASCII,
textToSet, outputSet.
*byteOrder*);

// constructor arguments: taginfo tag fieldtype count bytes
TiffOutputField exif_comment = new
TiffOutputField(TiffConstants.EXIF_TAG_USER_COMMENT.tag,
TiffConstants.EXIF_TAG_USER_COMMENT,
TiffFieldTypeConstants.FIELD_TYPE_UNDEFINED,
b.length, b);



Joakim



On 22 May 2016 at 15:29, Benedikt Ritter <brit...@apache.org> wrote:

> Hello Joakim
>
> Joakim Knudsen <joakim.gr...@gmail.com> schrieb am Sa., 21. Mai 2016 um
> 19:29 Uhr:
>
> > Hi List!
> >
> > I'm working on an Android app, where I want to read and write "EXIF tags"
> > to JPEG files on the device. Sanselan 0.97 seems to work perfectly,
> > although it's a bit complicated to work with EXIF tags/directories.
> >
> > The specific tags I'm interested in, is EXIF_TAG_USER_COMMENT and
> > EXIF_TAG_IMAGE_DESCRIPTION.
> > According to the documentation I could find, UserComment is of field type
> > "undefined", whereas ImageDescription is of field type ASCII.
> >
> >
> http://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif/usercomment.html
> > http://www.awaresystems.be/imaging/tiff/tifftags/imagedescription.html
> >
> > What's the proper way of creating those tags, wrt. charset etc? I want as
> > wide as possible character support (æøå etc).
> >
> > I find different discussions online, with different advice. Seems two
> > constructors are going around, where the simpler one does not deal with
> > charset/encoding at all. This one uses the .create method:
> >
> > String textToSet = "Some Text æøå";
> >
> > TiffOutputField exif_comment = TiffOutputField.create(
> > TiffConstants.EXIF_TAG_USER_COMMENT,
> > outputSet.byteOrder, textToSet);
> >
> >
> > while this one uses the standard constructor:
> >
> > byte b[] = ExifTagConstants.EXIF_TAG_USER_COMMENT.encodeValue(
> > TiffFieldTypeConstants.FIELD_TYPE_ASCII,
> > textToSet, outputSet.byteOrder
> > );
> >
> > // constructor arguments: taginfo tag fieldtype count bytes
> > TiffOutputField exif_comment2 = new
> > TiffOutputField(TiffConstants.EXIF_TAG_USER_COMMENT.tag,
> > TiffConstants.EXIF_TAG_USER_COMMENT,
> > TiffFieldTypeConstants.FIELD_TYPE_UNDEFINED,
> > b.length, b);
> >
> > In this last one, the string to set has been converted to a byte array
> > first. But can/should I set the encoding anywhere?
> >
> > Is the field type even ASCII? This information seems to indicate it's
> > not ASCII...
> >
> >
> http://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif/usercomment.html
> >
> >
> > Need some help here, as you can see, to get this right. The second
> > approach above does seem to work in my app, but I'd like to be sure
> > I'm not somehow messing up the JPEGs on the deviced.
> >
>
> I've looked at the code of
> org.apache.commons.imaging.formats.tiff.taginfos.TagInfoGpsText
> (ExifTagConstants.EXIF_TAG_USER_COMMENT is an instance of TagInfoGpsText).
> Here are my observations:
>
> - The FieldType parameter, which you have set to
> TiffFieldTypeConstants.FIELD_TYPE_ASCII is never used in the implemenation
> of encodeValue(FieldType, Object, ByteOrder)
> - When converting the input String to byte array, String.getBytes(String
> charsetName) is used
> - For charsetName "US-ASCII" is always used (it can not be configured by
> the user)
>
> So my guess is, that the code will not handle characters not in the
> US-ASCII charset correctly.
>
> Benedikt
>
>
> >
> >
> >
> > Joakim
> >
>


Re: Creating EXIF tags (TiffOutputField) the right way

2016-05-31 Thread Joakim Knudsen
Following a post on the User-Commons-Apache log (from 2012), I ended up
with the following code which seems to work.
It writes proper Unicode, which I can read back successfully using
ExifTool. I also see the comment nicely in Windows Explorer, and under File
> Properties.
Note I changed the field type from ASCII to FIELD_TYPE_UNDEFINED, otherwise
(with ASCII) it did not work. At least Windows couldn't make sense of the
EXIF data.

// http://osdir.com/ml/user-commons-apache/2012-03/msg00046.html
byte[] unicodeMarker = new byte[]{ 0x55, 0x4E, 0x49, 0x43, 0x4F, 0x44,
0x45, 0x00 };
byte[] comment = textToSet.getBytes(ENCODING_UTF16); // OR UTF-16BE if
the file is big-endian!
byte[] bytesComment = new byte[unicodeMarker.length + comment.length];
System.arraycopy(unicodeMarker, 0, bytesComment, 0, unicodeMarker.length);
System.arraycopy(comment, 0, bytesComment, unicodeMarker.length,
comment.length);

TiffOutputField exif_comment = new
TiffOutputField(TiffConstants.EXIF_TAG_USER_COMMENT,
TiffFieldTypeConstants.FIELD_TYPE_UNDEFINED,
bytesComment.length, bytesComment);


I can now write UserComment: "æøå" without problems :)



- Joakim


On 31 May 2016 at 17:39, Benedikt Ritter <brit...@apache.org> wrote:

> Hello Joachim,
>
> Joakim Knudsen <joakim.gr...@gmail.com> schrieb am Sa., 28. Mai 2016 um
> 21:10 Uhr:
>
> > Hi Benedikt, and thanks for replying!
> >
> > So, if FieldType is unused, maybe the alternative, simpler constructor is
> > more appropriate/correct to use?
> >
> > // try using the approach given in the example (modified from the GPS
> tag):
> > TiffOutputField exif_comment = TiffOutputField.create(
> > TiffConstants.EXIF_TAG_USER_COMMENT,
> > outputSet.byteOrder, textToSet);
> >
> > However, now Sanselan throws an ImageWriteException:
> > org.apache.sanselan.ImageWriteException: Tag has unexpected data type.
> >
> > So are you 100% sure field type should not be set (to ASCII)?
> >
>
> No, I'm just saying that it uses a hard coded encoding anyway :-)
>
>
> >
> > Next, you're saying the string to set (textToSet) is converted internally
> > to byte array, using US-ASCII encoding.
> > If I try writing "æøåæøå" to a file, I get "쎦쎸쎥쎦쎸쎥" when I copy the JPEG
> > out and check Properties in Windows Explorer.
> > If I write only ASCII characters, e.g. "Test", then that comes through
> just
> > fine.
> >
> > In summary, here is the code that works for me (except non-ASCII
> > characters):
> >
> >
> > *//
> >
> >
> http://mail-archives.apache.org/mod_mbox/commons-user/201203.mbox/%3CCAJm2B-mYCXYKuyu=Hs8UAZCpw-B=kwuz4gszfuobvzwun0l...@mail.gmail.com%3E
> > <
> >
> http://mail-archives.apache.org/mod_mbox/commons-user/201203.mbox/%3CCAJm2B-mYCXYKuyu=Hs8UAZCpw-B=kwuz4gszfuobvzwun0l...@mail.gmail.com%3E
> > >*byte
> > b[] = ExifTagConstants.EXIF_TAG_USER_COMMENT.encodeValue(
> > TiffFieldTypeConstants.FIELD_TYPE_ASCII,
> > textToSet, outputSet.
> > *byteOrder*);
> >
> > // constructor arguments: taginfo tag fieldtype count bytes
> > TiffOutputField exif_comment = new
> > TiffOutputField(TiffConstants.EXIF_TAG_USER_COMMENT.tag,
> > TiffConstants.EXIF_TAG_USER_COMMENT,
> > TiffFieldTypeConstants.FIELD_TYPE_UNDEFINED,
> > b.length, b);
> >
>
> The provided links indicate to me, that it is possible to write non ASCII
> characters. Are you sure your code looks like what Damjan suggested?
>
> Benedikt
>
>
> >
> >
> >
> > Joakim
> >
> >
> >
> > On 22 May 2016 at 15:29, Benedikt Ritter <brit...@apache.org> wrote:
> >
> > > Hello Joakim
> > >
> > > Joakim Knudsen <joakim.gr...@gmail.com> schrieb am Sa., 21. Mai 2016
> um
> > > 19:29 Uhr:
> > >
> > > > Hi List!
> > > >
> > > > I'm working on an Android app, where I want to read and write "EXIF
> > tags"
> > > > to JPEG files on the device. Sanselan 0.97 seems to work perfectly,
> > > > although it's a bit complicated to work with EXIF tags/directories.
> > > >
> > > > The specific tags I'm interested in, is EXIF_TAG_USER_COMMENT and
> > > > EXIF_TAG_IMAGE_DESCRIPTION.
> > > > According to the documentation I could find, UserComment is of field
> > type
> > > > "undefined", whereas ImageDescription is of field type ASCII.
> > > >
> > > >
> > >
> >
> http://www.awaresystems.be/imag

IPTC Caption-Abstract

2016-05-31 Thread Joakim Knudsen
Anyone know how to create this tag, and write it to a JPEG, using Sanselan?

IPTCType.IPTC_TYPE_CAPTION_ABSTRACT


Joakim


Re: Creating EXIF tags (TiffOutputField) the right way

2016-06-01 Thread Joakim Knudsen
Sure! That would also give even more scrutiny to the code. I'm not 100%
sure this is totally correct, but I got wonderful help from Phil Harvey
(ExifTool) to get the charset/encoding correct.
So I'm pretty confident. How do I contribute?

Btw, you wouldn't happen to know anything about IPTC and XMP, would you? It
seems the EXIF tags I'm writing (UserComment and ImageDescription) are not
enough for the comment to appear as a caption in image viewer software
(like Picasa etc). I was wondering (hoping) Sanselan could write the
following tags:

IPTC:Caption-Abstract
and
XMP:Description


Joakim

On 1 June 2016 at 14:55, Benedikt Ritter <brit...@apache.org> wrote:

> Hello Joakim,
>
> glad you found out what to do. This would make for a good addition to the
> user guide. Would you like to contribute your findings?
>
> Benedikt
>
> Joakim Knudsen <joakim.gr...@gmail.com> schrieb am Di., 31. Mai 2016 um
> 19:21 Uhr:
>
> > Btw, ENCODING_UTF16 is just a String = "UTF-16LE" (Little Endian)
> >
> > On 31 May 2016 at 19:20, Joakim Knudsen <joakim.gr...@gmail.com> wrote:
> >
> > > Following a post on the User-Commons-Apache log (from 2012), I ended up
> > > with the following code which seems to work.
> > > It writes proper Unicode, which I can read back successfully using
> > > ExifTool. I also see the comment nicely in Windows Explorer, and under
> > File
> > > > Properties.
> > > Note I changed the field type from ASCII to FIELD_TYPE_UNDEFINED,
> > > otherwise (with ASCII) it did not work. At least Windows couldn't make
> > > sense of the EXIF data.
> > >
> > > // http://osdir.com/ml/user-commons-apache/2012-03/msg00046.html
> > > byte[] unicodeMarker = new byte[]{ 0x55, 0x4E, 0x49, 0x43, 0x4F, 0x44,
> > > 0x45, 0x00 };
> > > byte[] comment = textToSet.getBytes(ENCODING_UTF16); // OR UTF-16BE if
> > the file is big-endian!
> > > byte[] bytesComment = new byte[unicodeMarker.length + comment.length];
> > > System.arraycopy(unicodeMarker, 0, bytesComment, 0,
> > unicodeMarker.length);
> > > System.arraycopy(comment, 0, bytesComment, unicodeMarker.length,
> > comment.length);
> > >
> > > TiffOutputField exif_comment = new
> > TiffOutputField(TiffConstants.EXIF_TAG_USER_COMMENT,
> > > TiffFieldTypeConstants.FIELD_TYPE_UNDEFINED,
> > bytesComment.length, bytesComment);
> > >
> > >
> > > I can now write UserComment: "æøå" without problems :)
> > >
> > >
> > >
> > > - Joakim
> > >
> > >
> > > On 31 May 2016 at 17:39, Benedikt Ritter <brit...@apache.org> wrote:
> > >
> > >> Hello Joachim,
> > >>
> > >> Joakim Knudsen <joakim.gr...@gmail.com> schrieb am Sa., 28. Mai 2016
> um
> > >> 21:10 Uhr:
> > >>
> > >> > Hi Benedikt, and thanks for replying!
> > >> >
> > >> > So, if FieldType is unused, maybe the alternative, simpler
> constructor
> > >> is
> > >> > more appropriate/correct to use?
> > >> >
> > >> > // try using the approach given in the example (modified from the
> GPS
> > >> tag):
> > >> > TiffOutputField exif_comment = TiffOutputField.create(
> > >> > TiffConstants.EXIF_TAG_USER_COMMENT,
> > >> > outputSet.byteOrder, textToSet);
> > >> >
> > >> > However, now Sanselan throws an ImageWriteException:
> > >> > org.apache.sanselan.ImageWriteException: Tag has unexpected data
> type.
> > >> >
> > >> > So are you 100% sure field type should not be set (to ASCII)?
> > >> >
> > >>
> > >> No, I'm just saying that it uses a hard coded encoding anyway :-)
> > >>
> > >>
> > >> >
> > >> > Next, you're saying the string to set (textToSet) is converted
> > >> internally
> > >> > to byte array, using US-ASCII encoding.
> > >> > If I try writing "æøåæøå" to a file, I get "쎦쎸쎥쎦쎸쎥" when I copy the
> > JPEG
> > >> > out and check Properties in Windows Explorer.
> > >> > If I write only ASCII characters, e.g. "Test", then that comes
> through
> > >> just
> > >> > fine.
> > >> >
> > >> > In summary, here is the code that works for me (except non-ASCII
> > >> > characters):
> > >> >
> > >> >
> >

Re: Creating EXIF tags (TiffOutputField) the right way

2016-05-31 Thread Joakim Knudsen
Btw, ENCODING_UTF16 is just a String = "UTF-16LE" (Little Endian)

On 31 May 2016 at 19:20, Joakim Knudsen <joakim.gr...@gmail.com> wrote:

> Following a post on the User-Commons-Apache log (from 2012), I ended up
> with the following code which seems to work.
> It writes proper Unicode, which I can read back successfully using
> ExifTool. I also see the comment nicely in Windows Explorer, and under File
> > Properties.
> Note I changed the field type from ASCII to FIELD_TYPE_UNDEFINED,
> otherwise (with ASCII) it did not work. At least Windows couldn't make
> sense of the EXIF data.
>
> // http://osdir.com/ml/user-commons-apache/2012-03/msg00046.html
> byte[] unicodeMarker = new byte[]{ 0x55, 0x4E, 0x49, 0x43, 0x4F, 0x44,
> 0x45, 0x00 };
> byte[] comment = textToSet.getBytes(ENCODING_UTF16); // OR UTF-16BE if the 
> file is big-endian!
> byte[] bytesComment = new byte[unicodeMarker.length + comment.length];
> System.arraycopy(unicodeMarker, 0, bytesComment, 0, unicodeMarker.length);
> System.arraycopy(comment, 0, bytesComment, unicodeMarker.length, 
> comment.length);
>
> TiffOutputField exif_comment = new 
> TiffOutputField(TiffConstants.EXIF_TAG_USER_COMMENT,
> TiffFieldTypeConstants.FIELD_TYPE_UNDEFINED, bytesComment.length, 
> bytesComment);
>
>
> I can now write UserComment: "æøå" without problems :)
>
>
>
> - Joakim
>
>
> On 31 May 2016 at 17:39, Benedikt Ritter <brit...@apache.org> wrote:
>
>> Hello Joachim,
>>
>> Joakim Knudsen <joakim.gr...@gmail.com> schrieb am Sa., 28. Mai 2016 um
>> 21:10 Uhr:
>>
>> > Hi Benedikt, and thanks for replying!
>> >
>> > So, if FieldType is unused, maybe the alternative, simpler constructor
>> is
>> > more appropriate/correct to use?
>> >
>> > // try using the approach given in the example (modified from the GPS
>> tag):
>> > TiffOutputField exif_comment = TiffOutputField.create(
>> > TiffConstants.EXIF_TAG_USER_COMMENT,
>> > outputSet.byteOrder, textToSet);
>> >
>> > However, now Sanselan throws an ImageWriteException:
>> > org.apache.sanselan.ImageWriteException: Tag has unexpected data type.
>> >
>> > So are you 100% sure field type should not be set (to ASCII)?
>> >
>>
>> No, I'm just saying that it uses a hard coded encoding anyway :-)
>>
>>
>> >
>> > Next, you're saying the string to set (textToSet) is converted
>> internally
>> > to byte array, using US-ASCII encoding.
>> > If I try writing "æøåæøå" to a file, I get "쎦쎸쎥쎦쎸쎥" when I copy the JPEG
>> > out and check Properties in Windows Explorer.
>> > If I write only ASCII characters, e.g. "Test", then that comes through
>> just
>> > fine.
>> >
>> > In summary, here is the code that works for me (except non-ASCII
>> > characters):
>> >
>> >
>> > *//
>> >
>> >
>> http://mail-archives.apache.org/mod_mbox/commons-user/201203.mbox/%3CCAJm2B-mYCXYKuyu=Hs8UAZCpw-B=kwuz4gszfuobvzwun0l...@mail.gmail.com%3E
>> > <
>> >
>> http://mail-archives.apache.org/mod_mbox/commons-user/201203.mbox/%3CCAJm2B-mYCXYKuyu=Hs8UAZCpw-B=kwuz4gszfuobvzwun0l...@mail.gmail.com%3E
>> > >*byte
>> > b[] = ExifTagConstants.EXIF_TAG_USER_COMMENT.encodeValue(
>> > TiffFieldTypeConstants.FIELD_TYPE_ASCII,
>> > textToSet, outputSet.
>> > *byteOrder*);
>> >
>> > // constructor arguments: taginfo tag fieldtype count bytes
>> > TiffOutputField exif_comment = new
>> > TiffOutputField(TiffConstants.EXIF_TAG_USER_COMMENT.tag,
>> > TiffConstants.EXIF_TAG_USER_COMMENT,
>> > TiffFieldTypeConstants.FIELD_TYPE_UNDEFINED,
>> > b.length, b);
>> >
>>
>> The provided links indicate to me, that it is possible to write non ASCII
>> characters. Are you sure your code looks like what Damjan suggested?
>>
>> Benedikt
>>
>>
>> >
>> >
>> >
>> > Joakim
>> >
>> >
>> >
>> > On 22 May 2016 at 15:29, Benedikt Ritter <brit...@apache.org> wrote:
>> >
>> > > Hello Joakim
>> > >
>> > > Joakim Knudsen <joakim.gr...@gmail.com> schrieb am Sa., 21. Mai 2016
>> um
>> > > 19:29 Uhr:
>> > >
>> > > > Hi List!
>> > > >
>> > > > I'm working on an Android app, where I want to read and write "EXIF
>> > tags&qu

Creating EXIF tags (TiffOutputField) the right way

2016-05-21 Thread Joakim Knudsen
Hi List!

I'm working on an Android app, where I want to read and write "EXIF tags"
to JPEG files on the device. Sanselan 0.97 seems to work perfectly,
although it's a bit complicated to work with EXIF tags/directories.

The specific tags I'm interested in, is EXIF_TAG_USER_COMMENT and
EXIF_TAG_IMAGE_DESCRIPTION.
According to the documentation I could find, UserComment is of field type
"undefined", whereas ImageDescription is of field type ASCII.
http://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif/usercomment.html
http://www.awaresystems.be/imaging/tiff/tifftags/imagedescription.html

What's the proper way of creating those tags, wrt. charset etc? I want as
wide as possible character support (æøå etc).

I find different discussions online, with different advice. Seems two
constructors are going around, where the simpler one does not deal with
charset/encoding at all. This one uses the .create method:

String textToSet = "Some Text æøå";

TiffOutputField exif_comment = TiffOutputField.create(
TiffConstants.EXIF_TAG_USER_COMMENT,
outputSet.byteOrder, textToSet);


while this one uses the standard constructor:

byte b[] = ExifTagConstants.EXIF_TAG_USER_COMMENT.encodeValue(
TiffFieldTypeConstants.FIELD_TYPE_ASCII,
textToSet, outputSet.byteOrder
);

// constructor arguments: taginfo tag fieldtype count bytes
TiffOutputField exif_comment2 = new
TiffOutputField(TiffConstants.EXIF_TAG_USER_COMMENT.tag,
TiffConstants.EXIF_TAG_USER_COMMENT,
TiffFieldTypeConstants.FIELD_TYPE_UNDEFINED,
b.length, b);

In this last one, the string to set has been converted to a byte array
first. But can/should I set the encoding anywhere?

Is the field type even ASCII? This information seems to indicate it's
not ASCII...
http://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif/usercomment.html


Need some help here, as you can see, to get this right. The second
approach above does seem to work in my app, but I'd like to be sure
I'm not somehow messing up the JPEGs on the deviced.



Joakim


Re: Sanselan support for writing IPTC fields

2017-03-18 Thread Joakim Knudsen
Hi

I'm also using Sanselan to read and write both IPTC and EXIF data (in an
Android app setting).
Seems to be working as it should, but maybe we can help each other out if I
share my code?

I did a bit of research on EXIF tags, and got help from Phil Harvey at
http://www.sno.phy.queensu.ca/~phil/exiftool/index.html
I've also got a lot of hassle dealing with charsets, encoding and
"international characters" since I'm working from a Norwegian locale.
Letters like "æ", "ø", and "å" required extra care. What I learned was to
set UTF-16 encoding, and make sure to add proper Unicode markers to the
text to write:

byte[] unicodeMarker = new byte[]{ 0x55, 0x4E, 0x49, 0x43, 0x4F, 0x44,
0x45, 0x00 };
byte[] comment = textToSet.getBytes(ENCODING_UTF16); // OR UTF-16BE if
the file is big-endian!
byte[] bytesComment = new byte[unicodeMarker.length + comment.length];
System.arraycopy(unicodeMarker, 0, bytesComment, 0, unicodeMarker.length);
System.arraycopy(comment, 0, bytesComment, unicodeMarker.length,
comment.length);
TiffOutputField exif_comment = new
TiffOutputField(TiffConstants.EXIF_TAG_USER_COMMENT,
TiffFieldTypeConstants.FIELD_TYPE_UNDEFINED,
bytesComment.length, bytesComment);

You can read more here: http://u88.n24.queensu.ca/exiftool/forum/index.php/
topic,7273.msg36826.html#msg36826



Since your question is on IPTC fields, I'll share the code I'm using for
"mirroring" tags in IPTC fields (I support both EXIF and IPTC, and maybe
later XMP). I have not done nearly as much research on IPTC as I did on
EXIF, so the following code is entirely based on sample/example code I
found online. It does seem to work, though

[image: Inline images 1]
If you fix your problems, probably we can improve the code together? Please
share what you learn!

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import android.content.ContentValues;
import android.util.Log;

import com.example.android.galleri.app.data.PhotoContract;

import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.sanselan.ImageReadException;
import org.apache.sanselan.ImageWriteException;
import org.apache.sanselan.Sanselan;
import org.apache.sanselan.common.IImageMetadata;
import org.apache.sanselan.common.byteSources.ByteSource;
import org.apache.sanselan.common.byteSources.ByteSourceFile;
import org.apache.sanselan.formats.jpeg.JpegImageMetadata;
import org.apache.sanselan.formats.jpeg.JpegImageParser;
import org.apache.sanselan.formats.jpeg.JpegPhotoshopMetadata;
import org.apache.sanselan.formats.jpeg.exifRewrite.ExifRewriter;
import org.apache.sanselan.formats.jpeg.iptc.IPTCRecord;
import org.apache.sanselan.formats.jpeg.iptc.IPTCType;
import org.apache.sanselan.formats.jpeg.iptc.JpegIptcRewriter;
import org.apache.sanselan.formats.jpeg.iptc.PhotoshopApp13Data;
import org.apache.sanselan.formats.tiff.TiffImageMetadata;
import org.apache.sanselan.formats.tiff.constants.TiffConstants;
import org.apache.sanselan.formats.tiff.constants.TiffFieldTypeConstants;
import org.apache.sanselan.formats.tiff.write.TiffOutputDirectory;
import org.apache.sanselan.formats.tiff.write.TiffOutputField;
import org.apache.sanselan.formats.tiff.write.TiffOutputSet;
import org.apache.sanselan.util.IOUtils;

public class ExifWriter
{

private static String ENCODING_UTF8 = "UTF-8";
private static String ENCODING_UTF16 = "UTF-16LE";

private static boolean WRITE_IPTC_DATA = true;

/**
 * This example illustrates how to add/update EXIF metadata in a JPEG file.
 *
 * @param jpegImageFile
 *A source image file.
 * @param values
 *tags to set + value
 * @throws IOException
 * @throws ImageReadException
 * @throws ImageWriteException
 */
public static void changeExifMetadata(File jpegImageFile,
ContentValues values)
throws IOException, ImageReadException, ImageWriteException
  

[imaging] Apache Commons Imaging, for Android?

2017-04-24 Thread Joakim Knudsen
Hi all

I've been using "Sanselan v0.97" in my Android app, with some success.
After a lot of searching the web, reading the Exif 2.2 standard, and using
software like Phil Harvey's ExifTool, I seem to be able to read and write
EXIF and IPTC metadata to JPEG files on an Android device. However, there
are some bugs in this version, and I have since learned that Sanselan has
been moved from incubator and renamed to Apache Commons Imaging.

I'm now wondering whether I should move from Sanselan to Commons Imaging.
Does anyone have experince using Commons Imaging on Android?


Joakim


Re: [jexl] How to use math functions with JEXL

2020-04-19 Thread Joakim Knudsen
Hi,

Did you import the Math library?

import java.lang.Math;


Joakim

søn. 19. apr. 2020, 07:21 skrev Greenberg, Gary :

> I am trying to evaluate an expression that beside simple arithmetic need
> to calculate square root.
>
> I tried sqrt(), Math.sqrt() and java.lang.Math.sqrt and nothing works
>
> I am always getting something like @1:1 undefined variable java.lang.Math.
>
> I did use before expr4j and it has all these functions built-in.
>
> Switched to JEXL, because need not only numeric, but also Boolean
> expressions.
>
> Can you also confirm if this type of expressions will work:
>
> a.equalsIgnoreCase(“XYZ”) && b.startWith(“http”)
>
> where a and b are variables in the JexlContext.
>
>
>
> Gary Greenberg
>
> Staff Software Engineer
>
> Data Product Development, BI-A
>
> E: ggree...@visa.com
>
> M: 650-269-7902
>
>
>
> [image: EmailSig-TaglineVersion]
>
>
>