how can i write unicode to xpcomment?

Started by huyaowen, July 22, 2014, 02:41:46 PM

Previous topic - Next topic

huyaowen

hello! the follow command line can write"some words" into the "xpcomment" of the desktop.jpg
exiftool  -xpcomment="some words" desktop.jpg

just like this pic shown:

but ,if i want to write some unicode characters,like chinese words:"成功成功"
the follow command line cannt work:

exiftool  -xpcomment="成功成功" desktop.jpg

also failed used "-L"

thanks a lot.

Hayo Baan

Well, given you are running on windows, the answer is that you probably can't; Windows does not properly support UTF-8 on the command-line (at least not as far as I know). Furthermore XPComment is an EXIF tag and those tags actually have no character encoding so in effect cannot really hold the Chinese characters (you'd better use an XMP tag (e.g., Description) instead).

Note though that Exiftool, will write the characters just fine on a system that does support UTF-8 (like Linux or Mac OS X):
$ exiftool  -xpcomment="成功成功" ee.jpg
    1 image files updated
$ exiftool  -xpcomment ee.jpg
XP Comment                      : 成功成功


Perhaps installing a command-line interpreter that does support UTF-8 properly is a solution?

Hope this helps,
Hayo
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

XPComment is stored as Unicode UCS-2 (@Hayo: yes, the format in the ExifTool documentation is int8u, which is what Microsoft uses, even though the actual representation is int16u.  Perhaps they do this because it is always written little-endian, so they don't want it treated as int16u with the byte swapping that would occur if it got converted to big-endian EXIF).

So the bottom line is: any valid 16-bit unicode character may be represented in XPComment.

I suggest using a UTF-8 text editor to store the value to a UTF-8 text file, then use this command:

exiftool "-xpcomment<=file.txt" ee.jpg

Just be sure that the text editor doesn't store a leading byte order mark (BOM).

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

huyaowen

@Hayo @Phil:thanks.

file.txt method works perfect!  thanks all.


Could ExiftoolGui support to write image's parent folder's name into xpcomment? :P

Hayo Baan

Quote from: Phil Harvey on July 22, 2014, 06:42:55 PM
XPComment is stored as Unicode UCS-2 (@Hayo: yes, the format in the ExifTool documentation is int8u, which is what Microsoft uses, even though the actual representation is int16u.  Perhaps they do this because it is always written little-endian, so they don't want it treated as int16u with the byte swapping that would occur if it got converted to big-endian EXIF).

So the bottom line is: any valid 16-bit unicode character may be represented in XPComment.

Ah, I see, interesting: 16 bit characters. Why they didn't the choose to use the UTF-8 encoding for this is beyond me though (pretty standard nowadays, not?). Perhaps the internal windows Unicode implementation works with 16 bit Unicode numbers (which, to be honest would not be a good thing either as there are many more valid characters). Anyway, from what I read in the documentation, XPComment is basically a Windows and Microsoft-only tag so unless you're only working solely with Windows and MS products, probably not the best tag to use...

Quote from: huyaowen on July 22, 2014, 09:21:31 PM
Could ExiftoolGui support to write image's parent folder's name into xpcomment? :P
I don't have experience with the ExifToolGUI, so I can't really help you here. Sorry.
Doing this on the command-line shouldn't be too hard though. Perhaps something like this will work for you:
exiftool  -xpcomment'<${XPComment} ${Directory;s/^\.$/use Cwd; cwd();/e;s/.*\///;}
This will take the original XPComment (which must already exist), add a space and then the last part of the path of the directory (it uses the current directory if the file is in the current directory, the \. part). On windows, you'll need to use " instead of ' and you may also need to switch the \/ for a \\ in the regular expression.

Hope this helps :)

Cheers,
Hayo
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

Quote from: HayoBaan on July 23, 2014, 03:05:49 AM
Why they didn't the choose to use the UTF-8 encoding for this is beyond me though (pretty standard nowadays, not?).

Windows has been really slow with UTF-8 support since they hang on to their historic character representations for far too long. This is a huge PITA for file names, which effectively have no special character support on the command line.

QuoteXPComment is basically a Windows and Microsoft-only tag so unless you're only working solely with Windows and MS products, probably not the best tag to use...

Very true.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

huyaowen

thanks.
exiftool has a little more complicated 。