It is currently March 28th, 2024, 8:57 pm

Get Exif information

Tips and Tricks from the Rainmeter Community
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Get Exif information

Post by mak_kawa »

Hi all

If following is not a "Tips and Tricks", and rather well-known thing, or wrong article, please ignore.

Currently I am using Phil Harvey's famous Exiftool.exe via RunCommand plugin to get various Exif information from photo image in my slideshow skin. Probably it is the best way for it, but... simultaneous multiple instances of the Exiftool are rather heavy for my old PC.

I recently noticed that the GetDetailsOf method of Windows PowerShell can also get basic Exif information such as camera model, capture time, and exposure. And it is somewhat light and fast even for my PC. For example, I have tested to run 9 PowerShell instances simultaneously, but no significant performance impact can be detected.

GetExfInfo.ps1:

Code: Select all

$path = $Args[0]
$shell = New-Object -COMObject Shell.Application
$folder = Split-Path $path
$file = Split-Path $path -Leaf
$shellfolder = $shell.Namespace($folder)
$shellfile = $shellfolder.ParseName($file)

Write-Host Manufacturer: $shellfolder.GetDetailsOf($shellfile, 32)
Write-Host Model: $shellfolder.GetDetailsOf($shellfile, 30)
Write-Host Capture Time: $shellfolder.GetDetailsOf($shellfile, 12)
Write-Host Shutter Speed: $shellfolder.GetDetailsOf($shellfile, 259)
Write-Host Aperture: $shellfolder.GetDetailsOf($shellfile, 260)
Write-Host Focal Length: $shellfolder.GetDetailsOf($shellfile, 262)
Write-Host ISO Value: $shellfolder.GetDetailsOf($shellfile, 264)
Output example:

Code: Select all

Manufacturer: Panasonic
Model: DMC-QQ
Capture Time: ‎2020/‎09/xx yy‎:zz
Shutter Speed: ‎1/160 Sec.
Aperture: f/5.6
Focal Length: ‎60 mm
ISO Value: ISO-200
Measure example:

Code: Select all

[GetExifData]
Measure=Plugin
Plugin=RunCommand
Program=powershell
Parameter=#CURRENTPATH#GetExifData.ps1 """[FilePath]"""
OutputType=ANSI
Substitute="?":""
DynamicVariables=1
Remarks1: In the PowerShell, a RegExp-related error occurs when some special character (ex. parenthesis) are included in the path name. The error can be avoided by enclosing the path string with quotations. But in the Parameter= option, Rainmeter seems to remove quotations automatically when hands it to PowerShell. So, "magic quotes" is necessary (at least for me).
Remarks2: There is a possibility that the PowerShell output sometimes includes some control code(?) as invisible Unicode characters. These are converted to "?" in ASCII output. So, substitution as above is necessary. Possibly, it is caused by local condition of my Windows, but not sure.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm

Re: Get Exif information

Post by SilverAzide »

mak_kawa wrote: September 28th, 2020, 5:00 am Remarks2: There is a possibility that the PowerShell output sometimes includes some control code(?) as invisible Unicode characters. These are converted to "?" in ASCII output. So, substitution as above is necessary. Possibly, it is caused by local condition of my Windows, but not sure.
You can resolve this with a slight change to your command measure and your .ps1 file.

First, in the Command measure, change the OutputType line to OutputType=UTF16.

Then, in your .ps1 file, add the line [Console]::OutputEncoding = New-Object -TypeName System.Text.UnicodeEncoding. I didn't try this with your code, but it should work (or something similar).
Gadgets Wiki GitHub More Gadgets...
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Get Exif information

Post by mak_kawa »

Hi SilverAzide

Thanks for suggestion. I will try these improvements later.

Actually, I did try several OutputType= in the measure, but didn't know [Console]::OutputEncoding=, so failed at all. :-)
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Get Exif information

Post by mak_kawa »

Hi SilverAzide

I tried your suggestion, but unfortunately, I have failed... :-)

Basically, your suggestion works well, but some Unicode invisible characters are still in the output string. So, time conversion using TimeStampFormat= option in Time measure failed.

Probably, I have to use Unicode syntax as [x0000] in the prior substitution or in the TimeStampFormat option. But sadly, I don't know what are the invisible characters (!!) and how to describe them in the [x0000] format... I looked them using binary editor, but... alas, definitely I have to learn about basics of the Unicode syntax. :-)

For now, I have reverted my skin code back to ASCII output, really shame.
User avatar
Yincognito
Rainmeter Sage
Posts: 7027
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Get Exif information

Post by Yincognito »

mak_kawa wrote: September 28th, 2020, 11:52 pm Hi SilverAzide

I tried your suggestion, but unfortunately, I have failed... :-)

Basically, your suggestion works well, but some Unicode invisible characters are still in the output string. So, time conversion using TimeStampFormat= option in Time measure failed.

Probably, I have to use Unicode syntax as [x0000] in the prior substitution or in the TimeStampFormat option. But sadly, I don't know what are the invisible characters (!!) and how to describe them in the [x0000] format... I looked them using binary editor, but... alas, definitely I have to learn about basics of the Unicode syntax. :-)

For now, I have reverted my skin code back to ASCII output, really shame.
If you're right about the invisible characters, you may be talking about the BOM character, i.e. [\xFEFF]. I have a thread on a similar issue in the Bugs & Features section, where Brian was kind enough to point me in the right direction.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Get Exif information

Post by mak_kawa »

Hi Yincognito

Thank you for response.

Yes, the binary dump of the result with [Console]::OutputEncoding = New-Object -TypeName System.Text.UnicodeEncoding in ps1 script and OutputType=UTF16 in RunCommand is as follows;
exif_binary.png
(Sorry, I don't know how to output binary dump as text...)

So, as far as I see, included invisible unicode characters are;
1) U+FEFF BYTE ORDER MARK
2) U+200E LEFT-TO-RIGHT MARK
3) U+200F RIGHT-TO-LEFT MARK

The 1) in the head of output is as you pointed out. Problem is 2) and 3) around date/time string. I don't know why they are included in the PowerShell output, but maybe caused from my local condition of Windows. For example, the unit of exposure time is Japanese character "秒(U+79D2)" instead of "sec.".

I use the date/time string as TimeStamp in Time measure to get weekday string from it. Unicode invisible characters are awkward problem in this conversion. Maybe use of [\x0000] expression solve this problem, but I don't try yet.
When the PowerShell script runs in ANSI mode, unicode invisible characters in the date/time string are replaced with "?" as ?2020/?09/?06 ??11:56, so it is easy to remove "?" with substitution, and TimeStamp conversion works well with no problem.
You do not have the required permissions to view the files attached to this post.
User avatar
Yincognito
Rainmeter Sage
Posts: 7027
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Get Exif information

Post by Yincognito »

mak_kawa wrote: October 8th, 2020, 1:12 pm Hi Yincognito

Thank you for response.

Yes, the binary dump of the result with [Console]::OutputEncoding = New-Object -TypeName System.Text.UnicodeEncoding in ps1 script and OutputType=UTF16 in RunCommand is as follows;
exif_binary.png
(Sorry, I don't know how to output binary dump as text...)

So, as far as I see, included invisible unicode characters are;
1) U+FEFF BYTE ORDER MARK
2) U+200E LEFT-TO-RIGHT MARK
3) U+200F RIGHT-TO-LEFT MARK

The 1) in the head of output is as you pointed out. Problem is 2) and 3) around date/time string. I don't know why they are included in the PowerShell output, but maybe caused from my local condition of Windows. For example, the unit of exposure time is Japanese character "秒(U+79D2)" instead of "sec.".

I use the date/time string as TimeStamp in Time measure to get weekday string from it. Unicode invisible characters are awkward problem in this conversion. Maybe use of [\x0000] expression solve this problem, but I don't try yet.
When the PowerShell script runs in ANSI mode, unicode invisible characters in the date/time string are replaced with "?" as ?2020/?09/?06 ??11:56, so it is easy to remove "?" with substitution, and TimeStamp conversion works well with no problem.
Yeah, it seems those 2) and 3) characters appear for other folks, not just for you - and nobody seems to know why they're there. My guess is that they might be marking something in the string, I don't think it's necessarily related to the language, as those characters make sense for Arabic or Hebrew and not so much for Japanese.

Anyway, I thik it's best to stick with OutputType=ANSI, that is almost always required in such cases. On the matter of replacing the characters, this can be done from the PowerShell script as well, e.g. Write-Host Capture Time: $($shellfolder.GetDetailsOf($shellfile, 12) -replace([char]8206,"") -replace([char]8207,"")) for Capture Time. Obviously it's easier to do it from the measure in Rainmeter, as there you only have to do it once (although there might be a way to make it more compact in PowerShell too, if all the data is included into one big Write-Host command while using an appropriate -Separator parameter), but just so you know.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Get Exif information

Post by mak_kawa »

Hi Yincognito

"Invisibles" are not only for me (and my Windows)... it is a soothing information. :-)
-replace([char]8206,"")
This function(?) is good to know. I will try it later. "8206" is a decimal expression of "U+200E"? Ah (...click...) 16x16x16x2+14=8206, OK. Maybe (...Googling...) I can also describe as "0x200E".
Sorry, such story is a bit difficult and time-consuming for me. :-)
User avatar
Yincognito
Rainmeter Sage
Posts: 7027
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Get Exif information

Post by Yincognito »

mak_kawa wrote: October 8th, 2020, 11:36 pm Hi Yincognito

"Invisibles" are not only for me (and my Windows)... it is a soothing information. :-)

This function(?) is good to know. I will try it later. "8206" is a decimal expression of "U+200E"? Ah (...click...) 16x16x16x2+14=8206, OK. Maybe (...Googling...) I can also describe as "0x200E".
Sorry, such story is a bit difficult and time-consuming for me. :-)
Yes, it's the decimal representation of those 2 characters. Just mentioning this as an alternative, maybe someday you'll need it - I didn't mean to make things more difficult and time-consuming for you (which is why I said you should stick with your already working approach). :D
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Jeff
Posts: 326
Joined: September 3rd, 2018, 11:18 am

Re: Get Exif information

Post by Jeff »

Code: Select all

[FilePath]
Measure=String
String="%USERPROFILE%\Downloads\canon_hdr_YES.jpg"

[GetExifData]
Measure=Plugin
Plugin=RunCommand
Parameter=magick identify -format '%[EXIF:*]' "[FilePath]"
OutputType=ANSI
DynamicVariables=1
This code is brought by today's sponsor, ImageMagick (because it has this dandy fancy function)
(i know it's a scratching-the-left-part-of-your-head-using-the-right-hand situation but this is a fix for school and work computers that blocked powershell through group policies)