What this does is two things:
1) Use a simple PowerShell .ps1 script to get the image width and height and return them as a string "width|height".
2) Use a simple Lua script to break this string into separate "width" and "height" values, which can be returned to any measure or meter using Inline Lua Variables.
PSImageSize.ini (Skin):
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Metadata]
Name=PSImageSize
Author=JSMorley
Information=Demonstrates using PowerShell to get the width and height of an image,|and some simple Lua to break that string into separate elements.
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0
Version=Jan 27, 2018
[Variables]
ImageName=#@#Images\Lampoon.jpg
[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell.exe
Parameter=-NoProfile -ExecutionPolicy Bypass -Command "& '.\ImageSize.ps1' '#ImageName#'"
OutputType=ANSI
FinishAction=[!ToggleMeter MeterSize][!UpdateMeter MeterSize][!Redraw]
[Lua]
Measure=Script
ScriptFile=ImageSize.lua
Disabled=1
[MeterImage]
Meter=Image
ImageName=#ImageName#
H=300
PreserveAspectRatio=1
LeftMouseUpAction=[!CommandMeasure MeasureRun "Run"]
[MeterSize]
Meter=String
Y=5R
W=([&MeterImage:W]-10)
X=([&MeterImage:W] / 2)
StringAlign=Center
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Width: [&Lua:Split('[&MeasureRun]','Width')] | Height: [&Lua:Split('[&MeasureRun]','Height')]
UpdateDivider=-1
Hidden=1
DynamicVariables=1
Code: Select all
$imageFile = $args[0]
add-type -AssemblyName System.Drawing
$image = New-Object System.Drawing.Bitmap $imageFile
$imageWidth = $image.Width
$imageHeight = $image.Height
write-host -NoNewline "$imageWidth|$imageHeight"
Code: Select all
function Split(stringArg, dimensionArg)
if stringArg == '' then return 0 end
sep = '|'
dimElements = {}
for element in stringArg:gmatch('[^'..sep..']+') do table.insert(dimElements, element) end
if #dimElements ~= 2 then
print('stringArg of '..stringArg..' is invalid')
return 0
end
if string.upper(dimensionArg) == 'WIDTH' then
return dimElements[1]
elseif string.upper(dimensionArg) == 'HEIGHT' then
return dimElements[2]
else
print('dimensionArg of '..dimensionArg..' is invalid')
return 0
end
end