It is currently March 28th, 2024, 11:01 am

How to get the image size after resizing

Get help with creating, editing & fixing problems with skins
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to get the image size after resizing

Post by jsmorley »

chilio wrote:So if I understand this correctly:
- In case of formula, one may choose to use brackets
- Any other case: use brackets.



But here they shouldn't be used?
How does this work?
The option MeasureName that you use on meters is a special case, where you just use the name of the measure without [brackets]. MeasureName isn't going and "getting" the value of the measure as such, but is "binding" the measure to the meter. The end result is the same, but that is just how meters work.

The only other times you don't use the [brackets] is when an option is designed to assume that any reference to a measure name is unambiguously the number value of the measure. That is two cases:

1) In the Formula option of a Calc measure.
2) In an IfCondition test on any measure.

In all other cases, you will need to use [brackets] around the [MeasureName] to indicate that you want to "go get" the value of the measure. Note that [MeasureName] will return the string value of the measure, and [MeasureName:] will return the number value. In ALL cases where you use a [MeasureName] in an option, you must use DyanmicVariables=1 on the measure or meter using the [MeasureName].
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Re: How to get the image size after resizing

Post by chilio »

jsmorley wrote:The option MeasureName that you use on meters is a special case, where you just use the name of the measure without [brackets]. MeasureName isn't going and "getting" the value of the measure as such, but is "binding" the measure to the meter. The end result is the same, but that is just how meters work.
That makes sense! Thanks!
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to get the image size after resizing

Post by jsmorley »

chilio wrote: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 :)
You might not. I'm not particularly pushing that approach over the plugin. I would only suggest that there are two minor advantages to the PowerShell / Lua approach.

1) In order to get both the "width" and "height" of the image, you must use two instances of the plugin measure, which means the image is loaded from disk and analyzed twice.

2) In order to distribute your skin as a .rmskin, you will have to find and include both the 32bit and 64bit versions of the plugin in your .rmskin. Not a big deal, it's tiny, but it is just a tad more hassle when you create your .rmskin.

Entirely up to you, I really just wanted to see if it could be done reasonably gracefully with PowerShell...
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Re: How to get the image size after resizing

Post by chilio »

jsmorley wrote:You might not. I'm not particularly pushing that approach over the plugin. I would only suggest that there are two minor advantages to the PowerShell / Lua approach.

1) In order to get both the "width" and "height" of the image, you must use two instances of the plugin measure, which means the image is loaded from disk and analyzed twice.

2) In order to distribute your skin as a .rmskin, you will have to include both the 32bit and 64bit versions of the plugin in your .rmskin. Not a big deal, it's tiny, but it is just a tad more hassle when you create your .rmskin.

Entirely up to you, I really just wanted to see if it could be done reasonably gracefully with PowerShell...
Fair enough, making the skin more lightweight is a good point. (But that could be archived by making another plugin that returns both at once right?)

Is there an easy way to construct a 32-bit plugin from a 64-bit one? (Or do I have both of them on disk if I installed the plugin?)
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to get the image size after resizing

Post by jsmorley »

chilio wrote:Fair enough, making the skin more lightweight is a good point. (But that could be archived by making another plugin that returns both at once right?)

Is there an easy way to construct a 32-bit plugin from a 64-bit one? (Or do I have both of them on disk if I installed the plugin?)
If you are running the latest 4.2 beta of Rainmeter (or later) then both the 32bit and 64bit versions of the plugin are in your @Vault\Plugins folder in ...Documents\Rainmeter\Skins. If your are running 4.1 of Rainmeter, you will need to get them from the @Resources folder of that .rmskin I posted in that thread to demonstrate the ImageSize plugin.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to get the image size after resizing

Post by jsmorley »

And yes, that ImageSize plugin could (and probably should) be changed so that it uses a "parent / child" approach and can return either the width or height without loading the image twice. I'll have to look into that.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to get the image size after resizing

Post by balala »

chilio wrote:So if I understand this correctly:
- In case of formula, one may choose to use brackets
In case of the Formula options of Calc measures and the IfCondition options of any measure, usually brackets aren't needed. I say usually, because sometimes however, they also should have to be used. This is the case, eg if you're working with WebParser measures, which return numbers. These kind of measures are treated as strings (even if they are returning numbers), so have to convert these strings to their numeric value. This is done by the brackets.
chilio wrote:So if I understand this correctly:
- Any other case: use brackets.
Right.
And in both cases you should have to take care to not forget the DynamicVariables=1 option, which is absolutely needed in such cases.
chilio wrote:But here they shouldn't be used?
How does this work?
Here, where? In your code? If so, in this case they shouldn't have to be used, because the ImageSize plugin measures are retruning numeric values, which are used into the Formula options of Calc measures.
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Re: How to get the image size after resizing

Post by chilio »

balala wrote:In case of the Formula options of Calc measures and the IfCondition options of any measure, usually brackets aren't needed. I say usually, because sometimes however, they also should have to be used. This is the case, eg if you're working with WebParser measures, which return numbers. These kind of measures are treated as strings (even if they are returning numbers), so have to convert these strings to their numeric value. This is done by the brackets.

Right.
And in both cases you should have to take care to not forget the DynamicVariables=1 option, which is absolutely needed in such cases.

Here, where? In your code? If so, in this case they shouldn't have to be used, because the ImageSize plugin measures are retruning numeric values, which are used into the Formula options of Calc measures.
What I meant to ask was why it only seemed to be optional to omit the brackets (so I thought: let's use them everywhere for clearity) but was required to omit the same brackets earlier. (As you told me, thanks again for that one, I probably wouldn't have found that bug anytime soon without your help :) )

But apparently that has to do with the initial binding of a measure to an image. I still don't understand why that needs other syntax, but at least I now know how to work with it :)

PS: "Here" was at the place where I quoted you, which you couldn't find because the forum only copies one layer of quotation, something a noob with only about 10 posts doesn't notice ^^
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to get the image size after resizing

Post by jsmorley »

chilio wrote:What I meant to ask was why it only seemed to be optional to omit the brackets (so I thought: let's use them everywhere for clearity) but was required to omit the same brackets earlier. (As you told me, thanks again for that one, I probably wouldn't have found that bug anytime soon without your help :) )

But apparently that has to do with the initial binding of a measure to an image. I still don't understand why that needs other syntax, but at least I now know how to work with it :)
It's more or less a prehensile tail. The concept of "binding" a measure to a meter is part of the original functionality of Rainmeter, from day one. The whole idea of [SectionVariables] was added much, much later, and so we are left with a construct that might have been done differently if things hadn't "evolved" over time, and we didn't care as much as we do about "backwards compatibility".

The long and the short of it is:

You don't use [brackets] with MeasureName on meters. Ever.

You don't need [brackets] in Formula in Calc measures or IfConditions on any measure.
You CAN use them, but should only do so if for instance you want to use a modifier on the [SectionVariable] like [MeterName:W] or such. Then be sure to use DynamicVariables=1.

In all other cases, using the value of a measure as a [SectionVariable] requires the [brackets].
1) If used in an option value, you must use DynamicVariables=1 on the measure or meter using them.
2) If used in a !Bang in an Action option, [SectionVariables] (and #Variables#) are always already "dynamic", and DynamicVariables=1 is not needed.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to get the image size after resizing

Post by balala »

chilio wrote:(As you told me, thanks again for that one, I probably wouldn't have found that bug anytime soon without your help :) )
Probably this isn't a bug, right jsmorley?
Post Reply