Detect if a resource image doesn't exist
#1
As the title says how can you detect if a resource image doesn't exist?

In my studio and genre view I'm using a resource pack to display the study / genre icon like so:-

xml:
<control type="image">
<left>64</left>
<right>64</right>
<top>32</top>
<bottom>32</bottom>
<aspectratio>keep</aspectratio>
<texture background="true">$INFO[ListItem.label,resource://resource.images.studios.white/,.png]</texture>
</control>

Pretty standard, however if the resource add-on doesn't contain the image I want to fallback to a text label. However I can't find a way to detect that the image doesn't exist.

Any ideas?
Reply
#2
i'm not 100% sure, but i thought something like this will work:

xml:
<control type="image" id="1234">
    ...
    <texture background="true" fallback="empty.png">$INFO[ListItem.label,resource://resource.images.studios.white/,.png]</texture>
</control>
<control type="label">
    ...
    <visible>String.IsEqual(Control.GetLabel(1234), empty.png)</visible>
</control>
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#3
(2021-08-07, 21:12)ronie Wrote: i'm not 100% sure, but i thought something like this will work:

xml:
<control type="image" id="1234">
    ...
    <texture background="true" fallback="empty.png">$INFO[ListItem.label,resource://resource.images.studios.white/,.png]</texture>
</control>
<control type="label">
    ...
    <visible>String.IsEqual(Control.GetLabel(1234), empty.png)</visible>
</control>
Thanks, but unfortunately Control.GetLabel doesn't return any value for an image control, even though the wiki says it should return the texture name.

OK, so after some further testing it seem like the problem is because I'm trying to set the texture and get the label inside of an <itemlayout> Sad
Reply
#4
(2021-08-07, 22:12)roidy Wrote:
(2021-08-07, 21:12)ronie Wrote: i'm not 100% sure, but i thought something like this will work:

xml:
<control type="image" id="1234">
    ...
    <texture background="true" fallback="empty.png">$INFO[ListItem.label,resource://resource.images.studios.white/,.png]</texture>
</control>
<control type="label">
    ...
    <visible>String.IsEqual(Control.GetLabel(1234), empty.png)</visible>
</control>
Thanks, but unfortunately Control.GetLabel doesn't return any value for an image control, even though the wiki says it should return the texture name.

OK, so after some further testing it seem like the problem is because I'm trying to set the texture and get the label inside of an <itemlayout> Sad
unfortunately i'm on the same problem about fallback textlabel when image is empty and i have the same problem with the studio image any solution?
Reply
#5
(2021-08-07, 19:44)roidy Wrote: As the title says how can you detect if a resource image doesn't exist?

In my studio and genre view I'm using a resource pack to display the study / genre icon like so:-

xml:
<control type="image">
<left>64</left>
<right>64</right>
<top>32</top>
<bottom>32</bottom>
<aspectratio>keep</aspectratio>
<texture background="true">$INFO[ListItem.label,resource://resource.images.studios.white/,.png]</texture>
</control>

Pretty standard, however if the resource add-on doesn't contain the image I want to fallback to a text label. However I can't find a way to detect that the image doesn't exist.

Any ideas?

you should stick with the fallback attribute
e.g.
<texture fallback="defaultstudios.png" background="true" diffuse="*maybe">*path</texture>


i do this ,

xml:
<control description="aspect keep" type="group">
<visible>[Container.Content(studios) | String.IsEqual(ListItem.dbtype,studio)]</visible>
<control type="image">
<texture fallback="defaultstudios.png" background="true" diffuse="artworkdiffuse/$PARAM[artwork].png">$VAR[ImageLayout_$PARAM[artwork]]</texture>
<aspectratio scalediffuse="false" aligny="center" align="center">keep</aspectratio>
<bordersize>8</bordersize>
</control>
<control type="textbox">
<visible>false</visible>
<info>listitem.label</info>
<centertop>50%</centertop>
<align>center</align>
<wrapmultiline>true</wrapmultiline>
<left>15</left>
<right>15</right>
<font>font20_title</font>
</control>
</control>
Skins |  Titan M O D   •   S W A N (WIP)
Reply
#6
(2021-08-08, 10:41)mardukL Wrote: you should stick with the fallback attribute
e.g.
<texture fallback="defaultstudios.png" background="true" diffuse="*maybe">*path</texture>

Yep sure, I know you can fall back to a default icon, however that's not what I'm trying to achieve. What I'm trying to do is in the list layout have an image only if the image exists else have a text label.

I guess it's just not possible, no worries, thanks anyway.
Reply
#7
(2021-08-08, 13:18)roidy Wrote:
(2021-08-08, 10:41)mardukL Wrote: you should stick with the fallback attribute
e.g.
<texture fallback="defaultstudios.png" background="true" diffuse="*maybe">*path</texture>

Yep sure, I know you can fall back to a default icon, however that's not what I'm trying to achieve. What I'm trying to do is in the list layout have an image only if the image exists else have a text label.

I guess it's just not possible, no worries, thanks anyway.


Hm.. ok, now i remember i wanted something similiar a while back and stopped... :/

Maybe:


For The Label

use fallback

e.g. use linebreaks to put it off the screen

<label fallback="$INFO[ListItem.Label]">[CR][CR][CR][CR][CR][CR]$INFO[*THEIMAGEPATH]</label>

may not nice but worth a try


EDIT:
So, if the label path exist, the linebraks will move it out of "visability" - if not exist show the studio label, unsure if a textbox is needed instead of a label control

EDIT2: unsure about the best practice for placing the linebreaks
Skins |  Titan M O D   •   S W A N (WIP)
Reply
#8
(2021-08-08, 13:52)mardukL Wrote: Hm.. ok, now i remember i wanted something similiar a while back and stopped... :/

Maybe:


For The Label

use fallback

e.g. use linebreaks to put it off the screen

<label fallback="$INFO[ListItem.Label]">[CR][CR][CR][CR][CR][CR]$INFO[*THEIMAGEPATH]</label>

may not nice but worth a try


EDIT:
So, if the label path exist, the linebraks will move it out of "visability" - if not exist show the studio label, unsure if a textbox is needed instead of a label control

EDIT2: unsure about the best practice for placing the linebreaks


Umm, I haven't tested but I can't see that working as $INFO[*THEIMAGEPATH] will exist regardless of weather the actual image file exists.

For example the image path is built like so:-

$INFO[ListItem.label,resource://resource.images.studios.white/,.png]

So say that ListItem.Label contains "Netflix" then the $INFO will resolve to:- resource://resource.images.studios.white/Netflix.png

This will happen regardless of weather the resource pack contains a Netflix.png file and thus the label will never fallback to $INFO[List.Label]

Thanks anyway.
Reply
#9
(2021-08-08, 13:18)roidy Wrote:
(2021-08-08, 10:41)mardukL Wrote:  

Yep sure, I know you can fall back to a default icon, however that's not what I'm trying to achieve. What I'm trying to do is in the list layout have an image only if the image exists else have a text label.

I guess it's just not possible, no worries, thanks anyway.

Did you mean this?

Studiologo with fallback to text (example from Titan_Mod):

xml:
                    <control type="image" id="7999">
                        <visible>!String.IsEmpty(Control.GetLabel(7999)) + !String.IsEmpty(ListItem.Studio)</visible>
                        <width>130</width>
                        <height>90</height>
                        <aspectratio aligny="center" align="left">keep</aspectratio>
                        <fadetime>200</fadetime>
                        <texture background="true">$VAR[image_StudioLogo]</texture>
                        <colordiffuse condition="String.IsEqual(Skin.String(studiologos.path),resource://resource.images.studios.white/)">$VAR[AdvancedRatings_TextColor]</colordiffuse>
                    </control>
                    <control type="button" id="7998">
                        <visible>String.IsEmpty(Control.GetLabel(7999)) + !String.IsEmpty(ListItem.Studio)</visible>
                        <width max="200">auto</width>
                        <height>90</height>
                        <font>Reg20</font>
                        <label>$INFO[ListItem.Studio]</label>
                        <aligny>center</aligny>
                        <align>center</align>
                        <wrapmultiline>true</wrapmultiline>
                        <textcolor>$INFO[Skin.String(ViewDetailsTextColor)]</textcolor>
                        <disabledcolor>$INFO[Skin.String(ViewDetailsTextColor)]</disabledcolor>
                        <texturenofocus colordiffuse="$INFO[Skin.String(ViewDetailsTextColor)]">netflix/frame/slimframe_softedge.png</texturenofocus>
                        <textoffsetx>10</textoffsetx>
                        <textoffsety>7</textoffsety>
                        <enable>false</enable>
                    </control>


Image

Image
Reply
#10
(2021-08-08, 18:02)Fuchs2468 Wrote: Did you mean this?

Studiologo with fallback to text (example from Titan_Mod):

Thanks, but as pointed out in post 3 Control.GetLabel doesn't work on an image control (maybe not on any control) when used inside an <itemlayout> in a list. It works fine anywhere else just not in a list Sad
Reply
#11
@roidy 

Upps, sorry for confusing last post. a little awkward for my side.


Now last try

The resourceaddon img  will just visible if exist, it'll just work of you use a background image  (green) in my example (tint a white image).
If the img not exist the 2 control set before will be visible as they are not overlayed anymore, if resource image exist it'll naturally overlay this 2 controls (image bg + textlabel).

Not best but workin...

                   
                
xml:

                    <control type="image">
                        <texture background="true" colordiffuse="red" diffuse="**" fallback="defaultstudios.png">colors/white</texture>
                        <visible>Container.Content(studios) | string.isequal(listitem.dbtype,studio)</visible>
                    </control>
                    <control type="label">
                        <info>listitem.label</info>
                        <centertop>50%</centertop>
                        <font>font**name</font>
                        <align>center</align>
                        <aligny>center</aligny>
                        <textcolor>white</textcolor>
                    </control>
                    
                    <control type="image">
                        ...
                        <bordersize>$PARAM[artwork_bordersize]</bordersize>
                        <bordertexture colordiffuse="green">colors/white.png</bordertexture>
                        <texture background="true">**IMAGEPATH*</texture>
                        <aspectratio scalediffuse="false">scale</aspectratio>
                        
                        <visible>Container.Content(studios) | string.isequal(listitem.dbtype,studio)</visible>
                    </control>

Image
Skins |  Titan M O D   •   S W A N (WIP)
Reply
#12
(2021-08-08, 20:16)mardukL Wrote: @roidy 

Upps, sorry for confusing last post. a little awkward for my side.


Now last try

The resourceaddon img  will just visible if exist, it'll just work of you use a background image  (green) in my example (tint a white image).
If the img not exist the 2 control set before will be visible as they are not overlayed anymore, if resource image exist it'll naturally overlay this 2 controls (image bg + textlabel).

Not best but workin...

                   
                
xml:

                    <control type="image">
                        <texture background="true" colordiffuse="red" diffuse="**" fallback="defaultstudios.png">colors/white</texture>
                        <visible>Container.Content(studios) | string.isequal(listitem.dbtype,studio)</visible>
                    </control>
                    <control type="label">
                        <info>listitem.label</info>
                        <centertop>50%</centertop>
                        <font>font**name</font>
                        <align>center</align>
                        <aligny>center</aligny>
                        <textcolor>white</textcolor>
                    </control>
                    
                    <control type="image">
                        ...
                        <bordersize>$PARAM[artwork_bordersize]</bordersize>
                        <bordertexture colordiffuse="green">colors/white.png</bordertexture>
                        <texture background="true">**IMAGEPATH*</texture>
                        <aspectratio scalediffuse="false">scale</aspectratio>
                        
                        <visible>Container.Content(studios) | string.isequal(listitem.dbtype,studio)</visible>
                    </control>

Sorry I'm just not understanding how that works Sad
Reply
#13
(2021-08-08, 21:01)roidy Wrote:
(2021-08-08, 20:16)mardukL Wrote: @roidy 

Upps, sorry for confusing last post. a little awkward for my side.


Now last try

The resourceaddon img  will just visible if exist, it'll just work of you use a background image  (green) in my example (tint a white image).
If the img not exist the 2 control set before will be visible as they are not overlayed anymore, if resource image exist it'll naturally overlay this 2 controls (image bg + textlabel).

Not best but workin...

                   
                
xml:

                    <control type="image">
                        <texture background="true" colordiffuse="red" diffuse="**" fallback="defaultstudios.png">colors/white</texture>
                        <visible>Container.Content(studios) | string.isequal(listitem.dbtype,studio)</visible>
                    </control>
                    <control type="label">
                        <info>listitem.label</info>
                        <centertop>50%</centertop>
                        <font>font**name</font>
                        <align>center</align>
                        <aligny>center</aligny>
                        <textcolor>white</textcolor>
                    </control>
                    
                    <control type="image">
                        ...
                        <bordersize>$PARAM[artwork_bordersize]</bordersize>
                        <bordertexture colordiffuse="green">colors/white.png</bordertexture>
                        <texture background="true">**IMAGEPATH*</texture>
                        <aspectratio scalediffuse="false">scale</aspectratio>
                        
                        <visible>Container.Content(studios) | string.isequal(listitem.dbtype,studio)</visible>
                    </control>

Sorry I'm just not understanding how that works Sad
hm. i am bad at explaining.
i try again via adding description tags in the controls, you'll just have to care about

xml:
<control type="group">
    <description>group to be shown for studio items</description>
    <visible>Container.Content(studios) | string.isequal(listitem.dbtype,studio)</visible>
    
    <control type="image">
        <description>layer 1, always visible, i match the bordertexture of image control type which try to show studiologo exactly, colordiffuse a white png</description>
        <texture colordiffuse="ff131313" diffuse="**">colors/white.png</texture>
    </control>
    <control type="textbox">
        <description>textlabel 1, always visible, on top of layer 1,behind layer 2 prefer textbox over label type for wrapmultiline</description>
        <info>listitem.label</info>
        <wrapmultiline>true</wrapmultiline>
        <centertop>50%</centertop>
        <font>font**name</font>
        <align>center</align>
        <textcolor>white</textcolor>
    </control>
    
    <control type="image">
        <description>layer 2, JUST visible if path exist, the bordertexture is used to overlay layer 1 and textbox control type, colordiffuse a white png
if the logo png cannot be found this control type cannot be visible, therefore cannot overlay the always visible control types

Means if exist i lay over the previous 2 Control types
if empty i'll not be shown without adding an condition
        </description>
            <bordertexture colordiffuse="ff131313">colors/white.png</bordertexture> <!-- i lay over layer 1, but lay behind the studio logo -->
            <texture background="true">**IMAGEPATH var or resource only*</texture>
    </control>
</control>
Skins |  Titan M O D   •   S W A N (WIP)
Reply
#14
(2021-08-09, 10:11)mardukL Wrote: hm. i am bad at explaining.
i try again via adding description tags in the controls, you'll just have to care about

Thanks, now I understand. However that method has a problem for my use case, you can't set the aspect ratio of the resource image as it also changes the aspect ratio of the underlying border as can be seen in this image.

watch gallery


The top image has no aspect ratio set but the bottom uses <aspectratio>keep</aspectratio> so as not to distort the logos, but as you can see this also effects the border texture and reveals the label behind Sad

I need to rethink this view.... either make the items square of just scrap it altogether.

Big thanks though for taking the time to help Smile
Reply
#15
(2021-08-09, 10:58)roidy Wrote:
(2021-08-09, 10:11)mardukL Wrote: hm. i am bad at explaining.
i try again via adding description tags in the controls, you'll just have to care about

Thanks, now I understand. However that method has a problem for my use case, you can't set the aspect ratio of the resource image as it also changes the aspect ratio of the underlying border as can be seen in this image.

watch gallery


The top image has no aspect ratio set but the bottom uses <aspectratio>keep</aspectratio> so as not to distort the logos, but as you can see this also effects the border texture and reveals the label behind Sad

I need to rethink this view.... either make the items square of just scrap it altogether.

Big thanks though for taking the time to help Smile


hm. i canot test atm.but i think i got
workin result in using the diffuse attribute




<aspectratio scalediffuse="false">stretch</aspectratio> in the layer 1 image control
and
diffuse="**"
<aspectratio scalediffuse="false">scale</aspectratio> in the studio logo image control
EDIT or
<aspectratio scalediffuse="true">keep</aspectratio>in the studio logo image control


eg using an 1:1 img in diffuse attribute
watch gallery


EDIT 2:
Put my test code as reference


using an empty img =alpha 00, but keep bordertexture in layer 1
has benefit have the correct offset of the image control control type applied
xml:
    <bordertexture colordiffuse="green">artworkdiffuse$PARAM[unthemed_postfix]/$PARAM[artwork_name].png</bordertexture>
    <texture>colors/none.png</texture>


my test code, as i had to leave now for a while
xml:
<control type="group">
<description>ARTWORK</description>
<centerleft>50%</centerleft>
<width>$PARAM[artwork_size_w]</width>
<height>$PARAM[artwork_size_h]</height>

<control type="image">
<description>ARTWORK : BG / FRAME</description>
<texture diffuse="artworkdiffuse$PARAM[unthemed_postfix]/$PARAM[artwork_name]border.png">colors/white.png</texture>
<colordiffuse>$PARAM[artwork_frame_color]</colordiffuse>
</control>

<control type="group">
<visible>String.StartsWith(ListItem.Icon,default) | String.IsEqual(ListItem.Label,$LOCALIZE[284]) | [Container.Content(studios) | string.isequal(listitem.dbtype,studio)]</visible>
<control type="image">
<description>ARTWORK : workaround icons with alpha00 - fallback img - </description>
<left>$PARAM[artwork_bordersize]</left>
<top>$PARAM[artwork_bordersize]</top>
<right>$PARAM[artwork_bordersize]</right>
<bottom>$PARAM[artwork_bordersize]</bottom>

<bordersize>$PARAM[artwork_bordersize]</bordersize>
<bordertexture colordiffuse="ff131313">artworkdiffuse$PARAM[unthemed_postfix]/$PARAM[artwork_name].png</bordertexture>
<texture colordiffuse="00ffffff">artworkdiffuse$PARAM[unthemed_postfix]/$PARAM[artwork_name].png</texture>

</control>
<control type="textbox">
<description>label center</description>
<centertop>50%</centertop>
<width>$PARAM[artwork_size_w]</width>
<height>$PARAM[artwork_size_h]</height>
<font>CommonTag</font>
<align>center</align>
<wrapmultiline>true</wrapmultiline>
<textcolor>white</textcolor>
<selectedcolor>white</selectedcolor>
<label>$INFO[ListItem.Label]</label>
</control>
<control type="image">
<description>ARTWORK : workaround icons with alpha00 - layer 1 - need tp have aspact keep in real icon img</description>
<left>$PARAM[artwork_bordersize]</left>
<top>$PARAM[artwork_bordersize]</top>
<right>$PARAM[artwork_bordersize]</right>
<bottom>$PARAM[artwork_bordersize]</bottom>

<bordersize>$PARAM[artwork_bordersize]</bordersize>
<bordertexture colordiffuse="ff131313">artworkdiffuse$PARAM[unthemed_postfix]/$PARAM[artwork_name].png</bordertexture>
<texture background="true" colordiffuse="$PARAM[fallback_alpha_defaulticon_color]" diffuse="artworkdiffuse$PARAM[unthemed_postfix]/$PARAM[artwork_name].png">$VAR[ImageLayout_$PARAM[artwork_name]]</texture>
<aspectratio scalediffuse="true">keep</aspectratio>
</control>
</control>
...
</control>

Image
Skins |  Titan M O D   •   S W A N (WIP)
Reply

Logout Mark Read Team Forum Stats Members Help
Detect if a resource image doesn't exist0