mattihe has asked for the wisdom of the Perl Monks concerning the following question:

I'm using Image::IPTCInfo module for retrieving IPTC data
from jpg images. It works very well but unfortunately I have problems (atleast) with scandinavian
letters - such as ä ö å
When I print out IPTC data it gives me following, where ~^J should be letter ä
<entiteetti> <city>Ilmajoki</city> <date_created>20040722</date_created> <object_name>Maalla 1</object_name> <category>luo</category> <by-line>00020465</by-line> <keywords> <keyword>poika</keyword> <keyword>kes~^J</keyword> <keyword>kes~^Jloma</keyword> <keyword>lato</keyword> <keyword>maatalous</keyword> <keyword>maaseutu</keyword> <keyword>pelto</keyword> <keyword>lapsi</keyword> </keywords> </entiteetti>

Has anyone solved this kind of character problems.. What's this ~^J ?

-NewBie-


AddOn: Thanks for messages so far, this has lead me to furher information... The problem is actually with Macintosh in-compatibility.

So now I'm trying to find mac-ascii to regular converter... or something like that.

# ä from mac to pc root-2.04# perl -e 'open (F, "<kuvat.txt");my @asd = <F>;close F;forea +ch(@asd){@t=split("\t", $_);$t[6] =~ s/\x8A/\xE4/g;print $t[6]."\n";} +' This is the way... *nix = http://www.idevelopment.info/data/Programming/ascii_table/PROGR +AMMING_ascii_table.shtml http://www.asciitable.com Mac = http://www.evergreen.edu/biophysics/technotes/program/ascii_ext- +mac.htm Other scandinavian letters... Ä = \x80 -> \xC4 ä = \x8A -> \xE4 Ö = \x85 -> \xD6 ö = \x9A -> \xF6 Å = \x81 -> \xC5 å = \x8C -> \xE5

Replies are listed 'Best First'.
Re: IPTC data
by tachyon (Chancellor) on Aug 04, 2004 at 14:18 UTC

    ~^J is how the ä is being rendered. Now as it happens ~ is the last char in the standard ASCII table (char 126 0x7e \167) and ^J is typically used to represent \n 10 0x0A \012 ^J LF Line Feed. Obviously it is a charset issue with chars past the standard ASCII set. As to why? It is not the UTF-8 value for ä (which is 0xC3 0xA4). The OS and output of perl -v might help other monks. Also how are you viewing the file.

    I don't have access to any Scandanavian JPEGs but the first thing to check would be that you actually have ä 228 0xe4 in the raw data file. Something quick and dirty like:

    perl -ne "m/ä/ and die 'Found'" test.jpg # Win32 perl -ne 'm/ä/ and die "Found"' test.jpg # *nix

    If it is not actually in the raw data then you may just have to workaround it (unless you can determine the encoding) - a simple regex s/~^J/ä/g solution will almost certainly be the fastest if dirtiest fix. Perhaps try the HexDump() feature to see if it is an input issue or an output issue. If the input phase is working OK you should see 0xe4 is present.

    cheers

    tachyon

Re: IPTC data
by trantor (Chaplain) on Aug 04, 2004 at 14:14 UTC
    It looks like the non-ASCII characters are encoded in UTF-8 in the resulting XML file, which makes sense because if I'm not wrong UTF-8 encoding is the deafault for XML files if a

    <?xml version="1.0" encoding="ISO-8859-1"?>

    line is missing.

    The code section that prints keywords in Image::IPTCInfo does not seem to do any sort of conversion on the keywords it handles, so I can only conclude that those keywords were entered already encoded in UTF-8 (which is good) and you're viewing the exported XML file in an environment which does not understand UTF-8.