It is currently March 29th, 2024, 1:12 pm

FallbackImage for Image meter

Report bugs with the Rainmeter application and suggest features.
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

FallbackImage for Image meter

Post by death.crafter »

It often happens that we're dealing with dynamic images and have no control over whether the image file exists or not, e.g. image created by another app or plugin, or downloaded using webparser.

So if there was an option like FallbackImage in Image meter that would be nice, instead of logging errors.
from the Realm of Death
User avatar
JelleDekkers
Posts: 127
Joined: September 27th, 2017, 6:32 pm
Location: Netherlands

Re: FallbackImage for Image meter

Post by JelleDekkers »

You can do

Code: Select all

Substitute="":"<path to image>"
on the appropriate measure(s).
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: FallbackImage for Image meter

Post by death.crafter »

JelleDekkers wrote: March 4th, 2022, 9:10 am You can do

Code: Select all

Substitute="":"<path to image>"
on the appropriate measure(s).
How do you do that for an image returned by an external application
from the Realm of Death
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: FallbackImage for Image meter

Post by Yincognito »

death.crafter wrote: March 3rd, 2022, 5:06 am It often happens that we're dealing with dynamic images and have no control over whether the image file exists or not, e.g. image created by another app or plugin, or downloaded using webparser.

So if there was an option like FallbackImage in Image meter that would be nice, instead of logging errors.
I hate those logging errors as well. The irony is that the logging errors are indirectly my fault, since the devs chose to log them (and as errors) when they fixed a bug related to image meters, which I reported some time ago. Before that, there were no logging errors on missing images and life was great, LOL (bar the said bug, that is).

Having an option like FallbackImage wouldn't help here IMHO, since that image would be prone to the same behavior, if by any chance it is missing as well, not to mention that you can easily create a "fallback image" system in your skin via either native Rainmeter, Lua, PS or CMD. In native Rainmeter, the simplest ways are to just put your actual image on top of your fallback one (Method 1 below: requires reasonable opacity and similar dimensions to fully cover the underlying image, doesn't care about image names), or use a combination of measure name and image name options as the complete path to the image (Method 2 below: doesn't care about opacity or dimensions, requires the extensionless name of the actual image to be a composite of the name of the fallback image and some other characters). I simulated missing the actual image via the OnUpdateAction in the measure below, but you can try the brute force way too (e.g. move the actual image back and forth between where it's expected to be and some other place) - toggle between methods by uncommenting / commenting the relevant parts:

Code: Select all

[Variables]
ImageName0=
ImageName1=a
ImageIndex=0

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=47,47,47,255

---Measures---

[ImageName]
Measure=String
String=[#ImageName[#ImageIndex]]
OnUpdateAction=[!SetOption ActualImage Hidden #ImageIndex#][!SetVariable ImageIndex (1-#ImageIndex#)]
DynamicVariables=1

---Meters---

[Text]
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
Text="Fallback Image = a#ImageName0#.png#CRLF#Actual  Image = a#ImageName1#.png"

- Method 1 -

[FallbackImage]
Meter=Image
Y=0R
ImageName=#@#a#ImageName0#.png
DynamicVariables=1

[ActualImage]
Meter=Image
Y=0r
ImageName=#@#a#ImageName1#.png
DynamicVariables=1

- Method 2 -

; [ActualOrFallbackImage]
; Meter=Image
; Y=0R
; MeasureName=ImageName
; ImageName=#@#a%1.png
; DynamicVariables=1
The above code obviously needs some a.png (mandatory, as the fallback image) and aa.png (optional, as the actual one) in the @Resources folder of your skin, for testing.

In my view, those missing errors could be made into warnings instead, to not scare or annoy people off, since missing an image is not critical in a skin and sometimes actually has an intentional purpose, but that's just me. In the end, it's up to the devs to decide on this... :confused:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: FallbackImage for Image meter

Post by balala »

death.crafter wrote: March 4th, 2022, 11:30 am How do you do that for an image returned by an external application
Passing it through a String measure?
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: FallbackImage for Image meter

Post by Yincognito »

balala wrote: March 4th, 2022, 8:12 pm Passing it through a String measure?
He probably meant that there is no way using only a String measure to detect if an image (created or not by an external application) exists so he can operate the substitute in the said String measure... :???:

That detection can be performed using a little PS, Lua or batch script, or even by the Image meter itself though (if the methods I posted above are used). Assuming we correctly understood what he wrote.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: FallbackImage for Image meter

Post by balala »

Yincognito wrote: March 4th, 2022, 10:00 pm He probably meant that there is no way using only a String measure to detect if an image (created or not by an external application) exists so he can operate the substitute in the said String measure... :???:
Right, this cant be easily decided with any kind of Rainmeter code. What the String measure can do, is to apply an image path / name, IF the variable generated by the external program is empty or not.
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: FallbackImage for Image meter

Post by Yincognito »

balala wrote: March 5th, 2022, 8:17 am Right, this cant be easily decided with any kind of Rainmeter code. What the String measure can do, is to apply an image path / name, IF the variable generated by the external program is empty or not.
Indeed, this will work if the said program generates a file name variable at all. If it outputs to the same file name and the question is whether the file exist or not, the approach would be of less help. I guess it depends on the particularities in death.crafter's scenario, in the end. But it's good to have as many solutions as possible, of course. :thumbup:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: FallbackImage for Image meter

Post by balala »

Yincognito wrote: March 5th, 2022, 10:08 am and the question is whether the file exist or not, the approach would be of less help.
A lua script is indeed needed to decide this.
Yincognito wrote: March 5th, 2022, 10:08 am I guess it depends on the particularities in death.crafter's scenario, in the end.
Exactly.
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: FallbackImage for Image meter

Post by death.crafter »

Yincognito wrote: March 4th, 2022, 6:48 pm I hate those logging errors as well. The irony is that the logging errors are indirectly my fault, since the devs chose to log them (and as errors) when they fixed a bug related to image meters, which I reported some time ago. Before that, there were no logging errors on missing images and life was great, LOL (bar the said bug, that is).

Having an option like FallbackImage wouldn't help here IMHO, since that image would be prone to the same behavior, if by any chance it is missing as well, not to mention that you can easily create a "fallback image" system in your skin via either native Rainmeter, Lua, PS or CMD.
In my view, those missing errors could be made into warnings instead, to not scare or annoy people off, since missing an image is not critical in a skin and sometimes actually has an intentional purpose, but that's just me. In the end, it's up to the devs to decide on this... :confused:
Actually error logging isn't the point here. And yes, I can use Lua to detect if an image exists or not.

The point is having a fallback image is especially helpful when you don't have control over the image's existence. Also, if I am using an fallback image, then I know that that image exists. And if it doesn't then you can log errors cause that's definitely one.

Anyway, let's see what the devs have to say about this
from the Realm of Death