It is currently April 20th, 2024, 12:40 pm

How to get the image size after resizing

Get help with creating, editing & fixing problems with skins
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

How to get the image size after resizing

Post by chilio »

Hey everyone!

I have trouble finding a way to get the actual image size of the image file.
What I'm trying to do:

Code: Select all

[MeterImage]
Measure=Plugin
Plugin=Plugins\QuotePlugin.dll
PathName=#FolderPath#
Subfolders=1
FileFilter=*.jpg;*.jpeg;*.png;*.bmp
UpdateDivider=1

[Image]
Meter=IMAGE
MeasureName=[MeterImage]
PreserveAspectRatio=1
X=0
Y=0
W=600
H=600
; Code I'm trying to implement, which should probably go into a calc measure, but first I'm trying to get at least some of this to work.
ActualW=[MeterImage:W]/Max([MeterImage:W], [MeterImage:H])*#W#
ActualH=[MeterImage:H]/Max([MeterImage:H], [MeterImage:W])*#H#
But I found (somewhere on this forum, but on another computer -.-') that it's not possible to get the origional image sizes.

So that gets me to the question: how do I get the size of the image after resizing to bounds while preserving the aspect ratio?
Last edited by chilio on January 27th, 2018, 5:13 pm, edited 2 times in total.
User avatar
balala
Rainmeter Sage
Posts: 16148
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to get the image size after resizing

Post by balala »

Use the ImageSize plugin, available here: https://forum.rainmeter.net/viewtopic.php?p=101884#p101884
Download the ImageSize_3.0.rmskin package, available on the above link and install it. Beside the skin, the ImageSize plugin will also be installed. Studying the code of the skin you find out how to get the size of the image.
Try this and if you don't succeed, come back with the question.
User avatar
balala
Rainmeter Sage
Posts: 16148
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to get the image size after resizing

Post by balala »

chilio wrote:[Image]
...
MeasureName=[MeterImage]
And just one more: the above option, written correctly, is MeasureName=MeterImage, not MeasureName=[color=#FF0000][[/color]MeterImage[color=#FF0000]][/color] (use it without brackets).
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Re: How to get the image size after resizing

Post by chilio »

Thanks!
I got most of it to work, but one thing fails to run:

Code: Select all

[Variables]
ImageWidth = 800
ImageHeight = 800
ImageActualWidth =  ([FileWidth] > [FileHeight] ? #ImageWidth# : (#ImageHeight# / [FileHeight] * [FileWidth]))
ImageActualHeight = ([FileWidth] < [FileHeight] ? #ImageHeight# : (#ImageWidth# / [FileWidth] * [FileHeight]))

;--------------------------------------------
[MeterImage]
Measure=Plugin
Plugin=Plugins\QuotePlugin.dll
PathName=#FolderPath#
Subfolders=#IncludeSubFolders#
FileFilter=*.jpg;*.jpeg;*.png;*.bmp
UpdateDivider=#Interval#

;--------------------------------------------
[FileWidth]
Measure=Plugin
Plugin=ImageSize
ImageName=MeterImage
Dimension=Width
UpdateDivider=1

;--------------------------------------------
[FileHeight]
Measure=Plugin
Plugin=ImageSize
ImageName=MeterImage
Dimension=Height
UpdateDivider=1

;--------------------------------------------
When I wrote #ImageActualWidth#, the skin wouldn't run anymore:

Code: Select all

; This was accepted
ImageActualWidth =  ([FileWidth] > [FileHeight] ? #ImageWidth# : #ImageWidth#)
; While this wasn't
ImageActualWidth =  ([FileWidth] > [FileHeight] ? #ImageWidth# : (#ImageHeight# / [FileHeight] * [FileWidth]))
Any ideas?
Thanks for the help!

PS:
How do the brackets work? (https://docs.rainmeter.net/tips/measure-as-a-variable/ <= this wasn't quite clear to me tbh ^^' )
And just one more: the above option, written correctly, is MeasureName=MeterImage, not MeasureName=[MeterImage] (use it without brackets).
Last edited by chilio on January 26th, 2018, 7:40 pm, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 16148
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to get the image size after resizing

Post by balala »

chilio wrote:When I wrote #ImageActualWidth#, the skin wouldn't run anymore:

Code: Select all

; This was accepted
ImageActualWidth =  ([FileWidth] > [FileHeight] ? #ImageWidth# : #ImageWidth#)
; While this wasn't
ImageActualWidth =  ([FileWidth] > [FileHeight] ? #ImageWidth# : (#ImageHeight# / [FileHeight] * [FileWidth]))
Any ideas?
The ImageName option of both the [FileWidth] and [FileHeight] measure should be ImageName=[color=#FF0000][[/color]MeterImage[color=#FF0000]][/color] (with brackets). This also requires to add to both measures, the DynamicVariables=1 option.
Beside this, you can't define the ImageActualWidth and ImageActualHeight variables in the [Variables] section as you did, because they also would require setting the dynamic variables. But the [Variables] section (as same as the [Rainmeter] section) doesn't support dynamic variables. I'd probably create two Calc measures, then would use those measures, instead of the ImageActualWidth and ImageActualHeight variables:

Code: Select all

[MeasureImageActualWidth]
Measure=Calc
Formula=(( FileWidth > FileHeight ) ? #ImageWidth# : #ImageWidth# )

[MeasureImageActualHeight]
Measure=Calc
Formula= (( FileWidth > FileHeight ) ? #ImageWidth# : ( #ImageHeight# / FileHeight * FileWidth ))
Now replace the #ImageActualWidth# and #ImageActualHeight# variable values with [MeasureImageActualWidth] and [MeasureImageActualHeight] (or eventually MeasureImageActualWidth and MeasureImageActualHeight, if you're using them into formula option of some Calc measures or in IfCondition options).

Just one more observation: although this detail doesn't prevent the code to work well, [MeterImage] is in fact a measure. To avoid confusions, you should name it [MeasureImage].

I can't say more then this, because I don't know the whole code. If my solution doesn't solve your issue, please post the whole code of your skin.
chilio wrote:PS:
How do the brackets work? (https://docs.rainmeter.net/tips/measure-as-a-variable/ <= this wasn't quite clear to me tbh ^^' )
Practically brackets aren't required around the name of the measures every time you're using them into Formula options of the Calc measures and into IfCondition options (also see above). In every other cases, they are required. Using them, also requires to add the DyanmicVariables=1 option to the measure or meter where they are used.
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Re: How to get the image size after resizing

Post by chilio »

YASSSS, Thanks a lot!
The result:
Capture.PNG
*Shameless merge of visbubble, custom slideshow frame and that colour finder of fox the socks*

I still have stuff to figure out, but I should post those questions in new threads right?
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16148
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to get the image size after resizing

Post by balala »

chilio wrote:I still have stuff to figure out, but I should post those questions in new threads right?
I don't know, depends. If it's something else, probably yes.
It was my pleasure to help.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to get the image size after resizing

Post by jsmorley »

Just as an aside, there is an alternative to the ImageSize plugin that you might want to consider...

https://forum.rainmeter.net/viewtopic.php?f=119&t=27693
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Re: How to get the image size after resizing

Post by chilio »

balala wrote:Practically brackets aren't required around the name of the measures every time you're using them into Formula options of the Calc measures and into IfCondition options (also see above). In every other cases, they are required. Using them, also requires to add the DyanmicVariables=1 option to the measure or meter where they are used.
So if I understand this correctly:
- In case of formula, one may choose to use brackets
- Any other case: use brackets.
balala wrote:And just one more: the above option, written correctly, is MeasureName=MeterImage, not MeasureName=[color=#FF0000][[/color]MeterImage[color=#FF0000]][/color] (use it without brackets).
But here they shouldn't be used?
How does this work?
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Re: How to get the image size after resizing

Post by chilio »

jsmorley wrote:Just as an aside, there is an alternative to the ImageSize plugin that you might want to consider...

https://forum.rainmeter.net/viewtopic.php?f=119&t=27693
So if I understand it correctly, it does the same thing, but in a powershell instead of a plugin. Why would someone want that? (Seeing plugins are managed and only installed once, while powershell scripts aren't?)

Not bashing, just trying to understand :)