It is currently April 19th, 2024, 5:29 pm

Masking an image with PreserveAspectRatio=1

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

Masking an image with PreserveAspectRatio=1

Post by chilio »

Hey everyone!

I'm trying to mask an image:

Code: Select all

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

;--------------------------------------------
[Image]
Meter=IMAGE
MeasureName=MeasureImage
PreserveAspectRatio=1
X = 0
Y = 0
W = 800
H = 800
; Added this line
MaskImageName = #@#circle.png
When using the mask, PreserveAspectRatio seemed to switch to PreserveAspectRatio=0 (not in the code, but visually).
Is this a bug or anything like that or am I just not seeing something (again)? (I can only find that the ScaleMargins and Tile options cannot be used, nothing about PreserveAspectRatio. (https://docs.rainmeter.net/manual/meters/image/))
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Masking an image with PreserveAspectRatio=1

Post by jsmorley »

If MaskImageName is defined, then W and H define the size of the mask image, and the size of the meter. Whatever is defined as the primary image with ImageName or MeasureName is then masked into the mask image, displaying in any non-transparent areas of MaskImageName using a "fill" method that sizes and crops the image to fit while preserving the aspect ratio.
Any PreserveAspectRatio=1 setting will be applied to the "mask" image. The "parent" image will then automatically be masked onto / into the "mask" image, sizing and cropping the parent image to fit while maintaining the aspect ratio. PreserveAspectRatio does will not apply to the parent image when MaskImageName is used.
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Re: Masking an image with PreserveAspectRatio=1

Post by chilio »

jsmorley wrote:PreserveAspectRatio has no effect if you define BOTH the W and H of the Image meter. That causes a conflict that can't unambiguously be resolved...
Well, it does if you don't mask ^^ So far it just fit the full picture in the given bounds :) Just as the documentation says btw:
1: The image is scaled to fit within the bounds specified by W and/or H while preserving the aspect ratio.
So both is an option. (https://docs.rainmeter.net/manual/meters/image/)

But lets put that aside for a moment while we arrive at the next question: How do I only specify the Width or Height, while using the biggest of the 2? (I found which one is the biggest here: https://forum.rainmeter.net/viewtopic.php?f=5&t=27690)

Code: Select all

[MeasureImage]
Measure=Plugin
Plugin=Plugins\QuotePlugin.dll
PathName=#FolderPath#
Subfolders=1
FileFilter=*.jpg;*.jpeg;*.png;*.bmp
UpdateDivider=1
;--------------------------------------------
[FileWidth]
Measure=Plugin
Plugin=ImageSize
ImageName=[MeasureImage]
Dimension=Width
UpdateDivider=1
DynamicVariables=1
;--------------------------------------------
[FileHeight]
Measure=Plugin
Plugin=ImageSize
ImageName=[MeasureImage]
Dimension=Height
UpdateDivider=1
DynamicVariables=1
;--------------------------------------------
[Image]
Meter=IMAGE
MeasureName=MeasureImage
PreserveAspectRatio=1
X = 0
Y = 0
; Can I put an invalid value here so it only uses the other?
W = (( FileWidth >= FileHeight ) ? 800 : -1)
H = (( FileWidth < FileHeight ) ? 800 : -1)
MaskImageName = #@#circle.png
;--------------------------------------------
If I use an invalid input for W or H, will rainmeter ignore it and only use the other? Or is there a way to insert an if-statement inside an assignment?

edit: The code should be more understandable now (edited [image:W, H]).
Last edited by chilio on January 27th, 2018, 6:42 pm, edited 2 times in total.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Masking an image with PreserveAspectRatio=1

Post by jsmorley »

chilio wrote:Well, it does if you don't mask ^^ So far it just fit the full picture in the given bounds :) Just as the documentation says btw: So both is an option. (https://docs.rainmeter.net/manual/meters/image/)

But lets put that aside for a moment while we arrive at the next question: How do I only specify the Width or Height, while using the biggest of the 2? (I found which one is the biggest here: https://forum.rainmeter.net/viewtopic.php?f=5&t=27690)

Code: Select all

[MeasureImage]
Measure=Plugin
Plugin=Plugins\QuotePlugin.dll
PathName=#FolderPath#
Subfolders=1
FileFilter=*.jpg;*.jpeg;*.png;*.bmp
UpdateDivider=1
;--------------------------------------------
[FileWidth]
Measure=Plugin
Plugin=ImageSize
ImageName=[MeasureImage]
Dimension=Width
UpdateDivider=1
DynamicVariables=1
;--------------------------------------------
[FileHeight]
Measure=Plugin
Plugin=ImageSize
ImageName=[MeasureImage]
Dimension=Height
UpdateDivider=1
DynamicVariables=1
;--------------------------------------------
[Image]
Meter=IMAGE
MeasureName=MeasureImage
PreserveAspectRatio=1
X = 0
Y = 0
; Can I put an invalid value here so it only uses the other?
W = (( FileWidth >= FileHeight ) ? #ImageWidth# : -1)
H = (( FileWidth < FileHeight ) ? #ImageHeight# : -1)
MaskImageName = #@#circle.png
;--------------------------------------------
If I use an invalid input for W or H, will rainmeter ignore it and only use the other? Or is there a way to insert an if-statement inside an assignment?
Not sure I understand. If you use either the actual width as the W OR use the actual height as the H, then PreserveAspectRatio=1 must locally display the image in it's actual size.
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Re: Masking an image with PreserveAspectRatio=1

Post by chilio »

jsmorley wrote:Any PreserveAspectRatio=1 setting will be applied to the "mask" image. The "parent" image will then automatically be masked onto / into the "mask" image, sizing and cropping the parent image to fit while maintaining the aspect ratio. PreserveAspectRatio does will not apply to the parent image when MaskImageName is used.
Seems like I just reacted to a removed comment, whoops ^^

But say I want to apply the mask after fitting the image, is that possible?
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Re: Masking an image with PreserveAspectRatio=1

Post by chilio »

jsmorley wrote:Not sure I understand. If you use either the actual width as the W OR use the actual height as the H, then PreserveAspectRatio=1 must locally display the image in it's actual size.
In the code, I tried to only use the width or the height to resize the image, but in that case, I would only want to use the restricting dimension. I did use ImageSize instead of FileSize there, but that one is defined out of the scope of the posted code ^^' (I always try only to post the minimal needed code to understand the problem, this one went a bit wrong...)
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Masking an image with PreserveAspectRatio=1

Post by jsmorley »

chilio wrote:Seems like I just reacted to a removed comment, whoops ^^

But say I want to apply the mask after fitting the image, is that possible?
I don't think so. Any W and / or H and PreserveAspectRatio is applied to the mask image, not the parent image.

Perhaps you can use the values of the parent image in a round-about way to control the size of the mask image though...

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[MeasureWidth]
Measure=Calc
Formula=400

[MeasureHeight]
Measure=Calc
Formula=500
IfCondition=MeasureWidth > MeasureHeight
IfTrueAction=[!SetOption MeterImage W "[MeasureWidth]"][!SetOption MeterImage H ""]
IfFalseAction=[!SetOption MeterImage H "[MeasureHeight]"][!SetOption MeterImage W ""]

[MeterImage]
Meter=Image
ImageName=#@#Images\laughing.jpg
PreserveAspectRatio=1
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Masking an image with PreserveAspectRatio=1

Post by jsmorley »

The whole MaskImageName deal has some limitations, and you just might not be able to get what you want. As I said, any W or H is applied to the "mask" image, and then the "parent" image is masked into it, making it bigger if it needs to to fit, but otherwise just cropping it if it is bigger than the mask, leaving it in its actual original size.
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Re: Masking an image with PreserveAspectRatio=1

Post by chilio »

Hmm, the point is that the size of the mask image is fine, I just want to use a smaller image inside of it: (Thanks for showing me how to set only the [Image:W] or [Image:H] value btw!)

What I have without masking:
No mask.PNG
I'm trying to mask everything outside visbubble, but what I get:
Mask.PNG
Which is great for square pictures, not so much for the 16:9 and such pictures.
I want to try to mask only the part that's outside of visbubble in the first image.
Would such a thing be possible? (And if not, would it be possible within lua or a plugin?)
You do not have the required permissions to view the files attached to this post.
Last edited by chilio on January 27th, 2018, 7:38 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Masking an image with PreserveAspectRatio=1

Post by jsmorley »

I don't know of any way. If you create a mask image that is the size and shape of the visualizer meter, then any image you mask into that is going to be made to "fit" inside that. It will just be cropped to fit inside the mask image, but you have no real control over the W and H of the image, only the mask.