Skip to content

The IT Blog

IT, Tech, Data, …

  • Home
  • Blog
    Thoughts about IT, Data, Work Culture
  • HowTos
    Stuff that was hard to find but very helpfull.
  • Research
    Posts from my research activities during my University time
  • About
  • GitHub
  • RSS
  • Mastodon

Tag: Imagero

Imagero: EXIF Rotation Tag schreiben

Mit Imagero 329 hat folgender Java Code seltsamerweise eine NullpointerException geliefert. Mit der aktuellen Imagero Version 429 kann man das EXIF-Rotations Tag problemlos schreiben und damit JPEGs verlostlos und schnell drehen. Mit (oder bis) Version 423 wurde unter bestimmten Umständen das Orientation Tag doppelt geschrieben.

IOParameterBlock iopb = new IOParameterBlock(src);
iopb.setDestination(src);
JpegFile reader = (JpegFile) new ImageProcOptions(iopb).imageFile;
ExifApp1 app1 = (ExifApp1) reader.jmr.getMarker(ExifApp1.NAME, 0);
if (app1 == null) { // falls das Bild noch keine EXIF Daten enthält
    EXIF exif = new EXIF(new ImageFileDirectory());
    exif.set.orientation(Orientation.TOP_LEFT);
    MetadataUtils.insert(reader, new Marker[]{exif.createMarker()}, iopb);
} else { // Falls schon EXIF Daten im Bild sind
    app1.getExif().set.orientation(Orientation.TOP_LEFT);
    reader.saveImage(iopb);
}
iopb.close();

Orientation.TOP_LEFT steht dabei für die Ausrichtung. Zum Drehen sind die folgenden Werte relevant:

  • 0°: Orientation.TOP_LEFT
  • 180°: Orientation.BOTTOM_RIGHT
  • 90°: Orientation.RIGHT_TOP
  • 270°: Orientation.LEFT_BOTTOM

Daneben gibt es noch 4 weitere Werte, die das Bild entsprechend drehen und spiegeln:

  1        2       3      4         5            6           7          8

888888  888888      88  88      8888888888  88                  88  8888888888
88          88      88  88      88  88      88  88          88  88      88  88
8888      8888    8888  8888    88          8888888888  8888888888          88
88          88      88  88
88          88  888888  888888

Wobei 1-8 derart definiert ist:

The orientation of the camera relative to the scene, when the image was captured. The relation of the ‘0th row’ and ‘0th column’ to visual position is shown as below.

Value 0th Row 0th Column
1 top left side
2 top right side
3 bottom right side
4 bottom left side
5 left side top
6 right side top
7 right side bottom
8 left side bottom

Relavante Links:

  • Exif Spezifikation
  • jpegcrop Seite mit nützlichen Infos
  • JPEG Rotation and EXIF Orientation

JPEG Rotation and EXIF Orientation

Posted on 3. January 2011Categories JavaTags Bild, EXIF, Image, Imagero, Java, metadata

IPTC-Tags mit Imagero schreiben

Mit folgendem Java Code kann man mit Imagero (Version 398) ein IPTC-Feld (hier: Keyword) schreiben. Ist der Keywords-Eintrag im Bild noch nicht vorhanden, wird er erstellt, andernfalls wird “foo” der Liste hinzugefügt.

public class TestImagero {
    public static void main(String[] args) throws Exception {
        LicenseManager.install(new FranzGraf());
        String src = "a.JPG";
        IOParameterBlock iopb = new IOParameterBlock(src);
        IOParameterBlock iopbDst = new IOParameterBlock(src).setDestination(src);
        IPTCEntryCollection iec = MetadataUtils.getIPTC(iopb);
        iec.addEntry(IPTCEntryMeta.KEYWORDS, "foo".getBytes());
        MetadataUtils.insertIPTC(iec, iopbDst);
        iopb.close();
        iopbDst.close();
    }
}

Einen Eintrag namens “foo_2” entfernt man aus den Keywords folgendermaßen:

            IOParameterBlock iopb = new IOParameterBlock(src);
            IOParameterBlock iopbDst = new IOParameterBlock(src).setDestination(src);
            IPTCEntryCollection iec = MetadataUtils.getIPTC(iopb);
            IPTCEntry[] entries = iec.getEntries(IPTCEntryMeta.KEYWORDS);
            List removes = new ArrayList();
            for (IPTCEntry entry : entries) {
                if (new String(entry.getData()).equals("foo_2")) {
                    removes.add(entry);
                }
            }
            for (IPTCEntry rem : removes) {
                System.out.println(iec.removeEntry(rem));
            }
            MetadataUtils.insertIPTC(iec, iopbDst);
            iopb.close();
            iopbDst.close();
Posted on 26. December 2010Categories JavaTags Bild, Image, Imagero, Java, metadata

Imagero: Alle IPTC-Daten listen

Mit folgendem Code kann man mit Imagero (Version 398) auch ohne Lizenzdatei alle IPTC-Daten eines Bildes auflisten.


public class TestImagero {
    public static void main(String[] args) throws IOException {
        String src = "C:\temp\DSC03375a.JPG";
        IPTCEntryCollection iec = MetadataUtils.getIPTC(new IOParameterBlock(src));
        Enumeration entries = iec.entries();
        while (entries.hasMoreElements()) {
            IPTCEntry entry = entries.nextElement();
            String meta = entry.getEntryMeta().name;
            System.out.println(meta + ":" + entry);
        }
    }
}

Das erzeugt dann folgende Ausgabe mit einem Testbild, in dem ich alle verfügbaren Felder mit Hilfe von IrfanView gefüllt habe (jeweils mit “irfanView Feldbezeichnung):

Imagero META 3.50
Licensed to:
-----------
: Imagero
License type: non-commercial use only
Use on a server allowed: yes
URL: ANYURL
License valid up to version: 3.50
Expire date: 20.07.2010

Caption/Abstract:irfanView Caption
Writer/Editor:irfanView CaptionWriter
Headline:irfanView Headline
Special instructions:irfanView  SpecialInstructions
By-line:irfanView Author
By-line title:irfanView Author title
Credit:irfanView Credits/Rights
Source:irfanView source
Object name:irfanView ObjectName
Date created:20100718
City:irfanView city
Sublocation:irfanView sublocation
Province/State:irfanView provinceState
Country/Primary location name:irfanView country
Original transmission reference:irfanView transmission reference
Category:irfanView Category
Supplemental category:irfanView Supplemental Category
Supplemental category:irfanView Supplemental Category
Supplemental category:irfanView Supplemental Category
Supplemental category:irfanView Supplemental Category
Urgency:1
Keywords:irfanView Keyword1
Keywords:irfanView Keyword2
Keywords:irfanView Keyword3
Copyright notice:irfanView Copyright

Verwandte Posts:

  • Imagero: alle EXIF-Daten listen
Posted on 18. July 2010Categories JavaTags Imagero, IPTC, Java, metadata

Imagero: alle EXIF-Daten listen

Mit folgendem Code kann man mit Imagero (Version 398) auch ohne Lizenzdatei alle EXIF-Daten eines Bildes auflisten.


public class TestImagero {
    public static void main(String[] args) throws IOException {
        String src = "C:\temp\DSC03375.JPG";
        ImageFileDirectory[] ifds = MetadataUtils.getExif(new IOParameterBlock(src));
        for (ImageFileDirectory ifd : ifds) {
            for (IFD_Entry entry : ifd.get.entries()) {
                String desc = entry.get.entryMeta().getName();
                String type = entry.get.typeAsString();
                String value = entry.getValuesAsString(255);
                System.out.println(desc + ": " + type + ":" + value);
            }
        }
    }
}

Das erzeugt dann folgende Ausgabe mit einem Testbild:

Imagero META 3.50
Licensed to:
-----------
: Imagero
License type: non-commercial use only
Use on a server allowed: yes
URL: ANYURL
License valid up to version: 3.50
Expire date: 20.07.2010

ImageDescription: ASCII:SONY DSC
Make: ASCII:SONY
Model: ASCII:DSLR-A350
Orientation: SHORT:8
XResolution: RATIONAL:72/1,
YResolution: RATIONAL:72/1,
ResolutionUnit: SHORT:2
Software: ASCII:DSLR-A350 v1.00
DateTime: ASCII:2010:07:10 09:09:10
YCbCrPositioning: SHORT:2
ExifPointer: LONG:53835
Unknown: UNDEFINED:0x50 0x72 0x69 0x6e 0x74 0x49 0x4d 0x0 0x30 0x33 [...]
GPSInfoIFDPointer: LONG:54237
ExposureTime: RATIONAL:1/800,
FNumber: RATIONAL:56/10,
ExposureProgram: SHORT:3
ISOSpeedRatings: SHORT:200
ExifVersion: UNDEFINED:0221
DateTimeOriginal: ASCII:2010:07:10 09:09:10
DateTimeDigitized: ASCII:2010:07:10 09:09:10
ComponentsConfiguration: UNDEFINED:
CompressedBitsPerPixel: RATIONAL:8/1,
BrightnessValue: SRATIONAL:875/100,
ExposureBiasValue: SRATIONAL:0/10,
MaxApertureValue: RATIONAL:497/100,
MeteringMode: SHORT:5
LightSource: SHORT:11
Flash: SHORT:16
FocalLength: RATIONAL:1500/10,
MakerNote: UNDEFINED:0x53 0x4f 0x4e 0x59 0x20 0x44 0x53 0x43 0x20 [...]
UserComment: UNDEFINED:0x0 0x0 0x0 0x0 [...]
FlashPixVersion: UNDEFINED:0100
ColorSpace: SHORT:1
PixelXDimension: LONG:4592
PixelYDimension: LONG:3056
InteroperabilityIFDPointer: LONG:54410
FileSource: UNDEFINED:
SceneType: UNDEFINED:
CustomRendered: SHORT:0
ExposureMode: SHORT:0
WhiteBalance: SHORT:1
FocalLengthIn35mmFilm: SHORT:225
SceneCaptureType: SHORT:0
Contrast: SHORT:0
Saturation: SHORT:0
Sharpness: SHORT:0
GPSVersionID: BYTE:
GPSLatitude: RATIONAL:47/1, 39/1, 50789/1000,
GPSLatitudeRef: ASCII:N
GPSLongitude: RATIONAL:11/1, 10/1, 34656/1000,
GPSLongitudeRef: ASCII:E
GPSTimeStamp: RATIONAL:7/1, 9/1, 10/1,
GPSDateStamp: ASCII:2010:07:10
Compression: SHORT:6
Orientation: SHORT:8
XResolution: RATIONAL:72/1,
YResolution: RATIONAL:72/1,
ResolutionUnit: SHORT:2
JpegSoi: LONG:40294
JpegDataLength: LONG:2841
YCbCrPositioning: SHORT:2

Verwandte Posts:

  • Imagero: alle IPTC-Daten listen
[...]
Posted on 18. July 2010Categories JavaTags EXIF, Imagero, Java, metadata

Imagero und Vendor Notes / Fazit

Nachdem ich gestern schon geschrieben hatte, dass Sanselan Probleme mit den Venoder Notes /Maker Notes hat, hab ich mir  kurz  Imagero angeschaut. Kurzer Test um das Orientierung-Tag in JPEGs neu zu setzen führte dann aber zur leichten Ernüchterung:

Mit dem Code unten werden die Vendor Notes nicht falsch geschrieben – sondern gar nicht 🙁

    public static void main(String[] args) throws IOException {
        LicenseManager.install(new FranzGraf());
        String src = "C:\temp\src1.jpg";
        String dst = "C:\temp\src2.jpg";

        IOParameterBlock iopb = new IOParameterBlock(src);
        iopb.setDestination(dst);
        ImageProcOptions options = new ImageProcOptions(iopb);
        JpegFile reader = (JpegFile) options.imageFile;
        ExifApp1 app1 = (ExifApp1) reader.jmr.getMarker(ExifApp1.NAME, 0);
        if (app1 != null) {
            app1.getExif().set.orientation(Orientation.LEFT_BOTTOM);
            reader.saveImage(iopb);
        }
        iopb.close();
    }

Jetzt wollte ich eigentlich noch im Forum nachfragen, ob ich das nicht vielleicht anders machen muss – allerdings ist die Freischaltung leider noch nicht erfolgt. Letztlich ist das aber auch wieder nicht die Schuld von Imagero oder Java selbst. Es scheint ja auch nicht umsonst ein TIFF MakerNoteSafety-Tag zu geben. Ich habe mich auch kurz mit Elmar Baumann unterhalten, der in JPhotoTagger dasselbe Problem hatte. Also doch besser, EXIF und IPTC nur lesen und die Infos in Datenbank und XMP abzulegen? (Das zeigt einmal mehr den Nachteil von proprietären Formaten).

Prinzipiell ist die Idee super, die Originaldateien unangetastet zu lassen und sonst alles in XMP-Dateien abzulegen. Aber halt: wenn ich unterwegs bin, zeichne ich den Weg mit meinem GPS-Logger auf und geotagge meine Bilder anschließend mit locr. – Und spätestens danach sind die MakerNotes eh schon weg. Also ist die Entscheidung nach der “richtigen” Lib wieder zurück auf Start, wie schon im früheren Artikel:

  • Drew Noakes: IPTC/EXIF lesen/nicht schreiben, open source
  • Imagero: IPTX/EXIF/XMP lesen/schreiben, kostenlos für nichtkommerzeille Nutzung, nicht open source, wird aber weiterentwickelt!
  • Adobe XMP SDK: nicht ausreichend für Java verfügbar
  • Apache Sanselan: IPTC lesen/schreiben(bald?), EXIF lesen/schreiben, XMP lesen/schreiben, open source, aber derzeit aber offenbar nicht wirklich  gewartet, so dass auch Bugs nicht gefixed werden, für die schon ein Patch existiert (siehe hier).

Will man also das volle Paket EXIF/IPTC/XMP mindestens lesen, bleibt man bei Sanselan vs. Imagero:

open source aktuell Kosten
Imagero nein ja frei für nicht-kommerziell
Sanselan ja nein frei
IOParameterBlock iopb = new IOParameterBlock(src);
iopb.setDestination(dst);
ImageProcOptions options = new ImageProcOptions(iopb);
JpegFile reader = (JpegFile) options.imageFile;
ExifApp1 app1 = (ExifApp1) reader.jmr.getMarker(ExifApp1.NAME, 0);
if (app1 != null) {
app1.getExif().set.orientation(Orientation.LEFT_BOTTOM);
reader.saveImage(iopb);
}
iopb.close();
Posted on 18. March 2010Categories JavaTags EXIF, Image, Imagero, IPTC, Java, metadata, XMP2 Comments on Imagero und Vendor Notes / Fazit

Sanselan und Vendor Notes

Metadaten in Bildern sind in Java scheinbar echt gar nicht so einfach.  In einem früheren Artikel habe ich kurz aufgelistet, welche Metadata-Libraries ich immerhin schon mal ausgemacht habe. – Sanselan sah da ja schon gar nicht schlecht aus.

Bei einem ersten Test bin ich dann aber darauf gestoßen, dass scheinbar die Vendor Notes echte Probleme bereiten können. Ich wollte eigentlich nur die Exif-Daten auslesen und in eine andere Datei kopieren. Die eigentlichen Exif-Daten waren alle super. Die Vendor-Notes meiner Sony Alpha 350 sahen auch ganz gut aus (keine genauen Vergleiche) – ein Bild einer Canon Powershot A570 IS war schon anspruchsvoller. Ca. die Hälfte der Vendor-Notes waren verändert bis unbrauchbar 🙁

Brav wie ich bin, erst mal auf der Mailingliste nachgefragt… keine Antwort – hm. Also mal brav einen Bug eröffnet. Und danach gesehen, dass das Verhalten in der Doku quasi schon angekündigt ist:

Note that this uses the “Lossless” approach – in order to preserve data embedded in the EXIF segment that it can’t parse (such as Maker Notes), this algorithm avoids overwriting any part of the original segment that it couldn’t parse. This can cause the EXIF segment to grow with each update, which is a serious issue, since all EXIF data must fit in a single APP1 segment of the Jpeg image.
http://commons.apache.org/sanselan/api-release/org/apache/sanselan/formats/jpeg/exifRewrite/ExifRewriter.html

Tjo. Blöd. Klar Blöd auch von den Kameraherstellern, dass diese Einträge proprietär sind – aber noch dümmer, dass es unter Windows gefühlte 10.000 Programme gibt, die die Exif-Daten einfach ändern können und sich das mit Java langsam echt zu einem ernsthaften Problem auswächst.

Als nächstes versuche ich jetzt Imagero, der ist zwar nicht frei, aber vielleicht geht’s da wenigstens.

Posted on 13. March 2010Categories JavaTags EXIF, Image, Imagero, IPTC, Java, metadata, Sanselan

Java Library for reading & writing EXIF, XMP and IPTC in JPEGs

Finally it seems that I’ve found a pure Java Library that can read and write XMP Data to and from JPEGs!

In the past time I’ve been googling for such a library repeatedly. There are quite some libraries for just reading EXIF or IPTC data. Amongst others are Drew Noakes’ library and Imagero. As I am on the verge of adding more metadata functionality to my self-made image database I had 2 issues:

  1. A decision of how to store labels and descriptions to images: a database only without touching the images or IPTC, XMP within images (with cached information to a database). Finally I decided that I wanted to use XMP(or IPTC so that the information is kept close to the image.
  2. A library for this!

What I’ve found so far (incomplete listing as I came across QUITE some libs for reading data):

Imagero and Drew Noakes: Until now I was using Drew Noakes library for reding EXIF data – which was absolutely okay but couldn’t write any data 🙁 Imagero supports writing of IPTC and XMP (from what I’ve read) and is even free for non-commercial usage. But it’s not true open source and you need to request a licence every year (which works w/out problems!). Judging the work Andrey Kusnetsov (maintainer of Imagero) is putting into it I think, that’s quite acceptable.

Adobe XMP SDK: Adobe – as the inventor of XMP – has released an SDK for reading/writing XMP. Most of the SDK is written in C, the SDK Core is also available in Java (great!) but the functionality to get and write the XMP to and from files .. is not available as Java. Quite annoying.

Apache Sanselan: When searching for Apache Sanselan you most likely end up at the incubator-site which says that the project is in the stat of migrating into apache – the mailinglist also doesn’t work. The simple reason: Sanselan is already a part of Apache Commons. So, this new link is the place to go. The most interesting thing of Sanselan is the format support:

  • JPEG IPTC support: read (yes), write (soon), Can read IPTC data from exsiting JPEG/JFIF files WITHOUT modifying image data.
  • JPEG EXIF: read (yes), write (yes), Can read and write EXIF data to and from exsiting JPEG/JFIF files WITHOUT modifying image data.
  • XMP: read (yes), write (yes), Can read XMP XML (as as String) from […] JPEG […]. Can remove, insert and update XMP XML into existing JPEG files.

Update: the downside of Sanselan is that development seems to have stalled. The current release is 0.97 from February 14th, 2009. :-(((

Posted on 21. August 2009Categories JavaTags EXIF, Image, Imagero, IPTC, Java, metadata, Sanselan, XMP3 Comments on Java Library for reading & writing EXIF, XMP and IPTC in JPEGs
Imprint Proudly powered by WordPress