Option -L (use Windows 1252) when writing Tags

Started by Cactus26, January 24, 2024, 08:12:50 AM

Previous topic - Next topic

Cactus26

I've tried various variants using -L when writing tags, even using a file for the value. Also I tried using the charset option instead, all without success, the value is always considered to be UTF8.

Example
exiftool C:\Temp\file.JPG "-artist<=c:\temp\value" -L

When reading the option works. If I understand the documentation correctly, this option should also work when writing tags.
Cactus

Phil Harvey

Yes it does apply when writing.  But the EXIF Artist tag doesn't specify a character set (stupid EXIF specification), so no conversions are done for this tag.

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

Cactus26

Thanks, Phil,
In the meantime i found the discussion on this topic in the faq (https://exiftool.org/faq.html#Q10). Somewhere I have already noticed that the Exif specification is unclear in this respect. Another mess that the ExifTool has to deal with (that's why I don't even try to implement something like this myself).

But there is still one thing I don't understand: If I write and read a tag with the -L Option I should get the same string aganin regardless how it is stored. I would assume that this is symmetrical.
For the tag XPKeywords (also EXIF) this seems to work, but not for the artist tag. If I convert to UTF8 myself an leave out the -L option both cases work. What may be the reason for this?
Cactus

Phil Harvey

Hi Cactus,

Quote from: Cactus26 on January 25, 2024, 08:25:20 AMIf I write and read a tag with the -L Option I should get the same string aganin regardless how it is stored. I would assume that this is symmetrical.

Can you provide an example where you don't get the same thing back?

QuoteFor the tag XPKeywords (also EXIF) this seems to work, but not for the artist tag.

You should get the same thing back for the Artist tag too, but here the -L option has no effect.

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

Cactus26

Phil,
Thank you for your support!

The commands are:
exiftool -L "-Artist<=c:\temp\umlaute.txt" C:\Temp\finsteraarhorn\P1030015.JPG
exiftool -T -L -Artist C:\temp\finsteraarhorn\P1030015.JPG > c:\temp\umlaute.out.txt
The files needed you find here: https://magentacloud.de/s/XGSBxMyTFAYY62q (note that even the cloud application does not display the textfile correctly, the encoding has to be Windows1252). My impression is that the image file does not play a role.
Jürgen

Phil Harvey

Your command returns the same value for artist as you wrote (on Mac anyway, and in any other reasonable shell, but if you use PowerShell all bets are off because it is known to modify data in pipes).

> exiftool -L "-artist<=umlaute.txt" a.jpg
    1 image files updated
> exiftool -L -artist a.jpg > out.txt
> hexdump umlaute.txt
    0000: e4 f6 fc df c4 dc d6                            [.......]
> hexdump out.txt
    0000: 41 72 74 69 73 74 20 20 20 20 20 20 20 20 20 20 [Artist          ]
    0010: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 [                ]
    0020: 3a 20 e4 f6 fc df c4 dc d6 0a                   [: ........]

The byte sequence e4 f6 fc df c4 dc d6 is preserved.

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

Cactus26

Hi Phil,
Sorry, I had lost track. Actually, I had the problem of asymmetry in my application, where I read via JSON and write "normal" with direct specification of tag=value. In the first case I don't specify -L ("The JSON output is UTF-8 regardless of any -L or -charset option setting") and I convert myself (which I had forgotten). In the latter case I had specified -L.

Now when I tried to recreate the problem using this example, I was too sloppy and didn't look closely, I also have input=output in my shell. In my application I avoid -L now generally and convert myself in every case, this should be more symmetrical.
Cactus

FrankB

Maybe this info helps.

I had the same issue with ExifToolGui, and was able to solve most, if not all, by using an args file.

So: Write your commands in an args file, save the args file as utf8 and call exiftool using only the args file.
You can open a log window in ExifToolGui and see exactly what is sent, and even create a cmd or ps1 file.

The args file in ExifToolGui always contains:
-CHARSET
FILENAME=UTF8
-CHARSET
UTF8

this is the complete args file:

-echo4
{ready57}
-CHARSET
FILENAME=UTF8
-CHARSET
UTF8
-v0
-overwrite_original
-sep
*
-m
-c
%d°%.4f
-API
WindowsWideFile=1

-exif:artist=Jürgen
_IGP0001.jpg
-execute57

cmd file:
@echo off
chcp 65001
set ARGS="%TEMP%\exiftool.args"
echo #### Generated by ExifToolGui #####>%ARGS%
echo ^-echo4>>%ARGS%
echo ^{ready57}>>%ARGS%
echo ^-CHARSET>>%ARGS%
echo ^FILENAME=UTF8>>%ARGS%
echo ^-CHARSET>>%ARGS%
echo ^UTF8>>%ARGS%
echo ^-v0>>%ARGS%
echo ^-overwrite_original>>%ARGS%
echo ^-sep>>%ARGS%
echo ^*>>%ARGS%
echo ^-m>>%ARGS%
echo ^-c>>%ARGS%
echo ^%%d°%%.4f>>%ARGS%
echo ^-API>>%ARGS%
echo ^WindowsWideFile=1>>%ARGS%
echo ^>>%ARGS%
echo ^-exif:artist=Jürgen>>%ARGS%
echo ^_IGP0001.jpg>>%ARGS%
echo ^-execute57>>%ARGS%
exiftool -@ %ARGS%
del %ARGS%
pause

Powershell version:

#
# When you receive a message ".... cannot be loaded because running scripts is disabled on this system",
# Copy, paste the next line in a new window:
# Set-ExecutionPolicy bypass -Scope Process
# Then uncomment and execute.
#
# To permanently disable start ISE as admin and execute:
# Set-ExecutionPolicy bypass -Scope LocalMachine
#
# It is recommended to run this script with WMF 5.1.
# You can check your version by issueing the command: $PSVersionTable.PSVersion
#
try {
  [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
}
catch {
# The first time in ISE we get an "invalid handle". Write something with -VER and try again.
  exiftool -VER
  [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
}
# Set Working directory.
Set-Location "C:\Foto\2024-01-22"

# New-TemporaryFile may not be known.
try {
    $args = New-TemporaryFile
}
catch {
    $args = Get-Item ([System.IO.Path]::GetTempFilename())
}
Set-Content -Encoding UTF8 -Path $args -Value "#### Generated by ExifToolGui #####"
Add-Content -Path $args -Value "-echo4"
Add-Content -Path $args -Value "{ready57}"
Add-Content -Path $args -Value "-CHARSET"
Add-Content -Path $args -Value "FILENAME=UTF8"
Add-Content -Path $args -Value "-CHARSET"
Add-Content -Path $args -Value "UTF8"
Add-Content -Path $args -Value "-v0"
Add-Content -Path $args -Value "-overwrite_original"
Add-Content -Path $args -Value "-sep"
Add-Content -Path $args -Value "*"
Add-Content -Path $args -Value "-m"
Add-Content -Path $args -Value "-c"
Add-Content -Path $args -Value "%d°%.4f"
Add-Content -Path $args -Value "-API"
Add-Content -Path $args -Value "WindowsWideFile=1"
Add-Content -Path $args -Value ""
Add-Content -Path $args -Value "-exif:artist=Jürgen"
Add-Content -Path $args -Value "_IGP0001.jpg"
Add-Content -Path $args -Value "-execute57"
#echo4 triggers NativeCommand exception. ==>> 2>&1 | %{"$_"} <<= redirects Stderr to Stdout
exiftool -@ $args 2>&1 | %{"$_"}
Remove-Item -Path $args
pause

Cactus26

Thank you, FrankB, using an args file coded in UTF8 seems to me to be an analogous strategy to mine, that is convert to UTF8 myself in my PHOR application and avoid -L.

@Phil: I still have the suspicion that there is some asymmetry, can you please try the umlaut example again with the XPKeywords tag? My suspicion is that, unlike the artist tag, this tag is converted to UTF8 when it is written using -L.

Cactus

Phil Harvey

Hi Cactus,

The XPKeywords tag is converted symmetrically to UCS2 when writing, and from UCS2 when reading.  The external character set in both cases is set by the -charset or -L option.

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

FrankB

Quote from: Cactus26 on January 29, 2024, 07:48:31 AMThank you, FrankB, using an args file coded in UTF8 seems to me to be an analogous strategy to mine, that is convert to UTF8 myself in my PHOR application and avoid -L.

Yes, It sure looks a lot like it. But the lines -CHARSET UTF8 are crucial to me. They tell Exiftool your data is UTF8, and also that you want UTF8 back. Phil will correct me hopefully if I'm wrong.

Also I wonder about this: When you pipe the output to a txt file via '> out.txt', the output IS UTF8. But the file does not contain a BOM. (Byte Order Mark) That is no requirement according to specs, but it could be that some Windows Programs rely on it.

Anyway: My post was only meant to help you, if it's confusing, forget it!

Phil Harvey

#11
Quote from: FrankB on January 29, 2024, 03:32:28 PMthe lines -CHARSET UTF8 are crucial to me. They tell Exiftool your data is UTF8, and also that you want UTF8 back. Phil will correct me hopefully if I'm wrong.

Correct, but these lines aren't crucial since UTF8 is the default (see here and here).

But -charset filename=utf8 is crutial because the default is no conversion for file names.

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