Attract-Mode Support Forum

Attract-Mode Support => General => Topic started by: walknight on August 07, 2020, 05:08:45 PM

Title: How to check the width/height of artwork
Post by: walknight on August 07, 2020, 05:08:45 PM
The theme I'm using has this code
Code: [Select]
local bgart = fe.add_artwork( "flyer", flw*0.2, 0, flw*0.6, 0);
bgart.preserve_aspect_ratio = true;
That is, it scales the image width to 60% of screen width and scales the height accordingly to keep the original aspect ratio.
But when I have an artwork in landscape direction, the scaled height is too short to fill the screen (see attached pic).

So I want to check the actual dimension of the image and scale it differently, either by width or by height.
I tried this code
Code: [Select]
    local bgart = fe.add_artwork( "flyer", flw*0.2, 0, flw*0.6, 0);
    bgart.preserve_aspect_ratio = true;

    if ( bgart.height < flh )
    {
      bgart.height = flh;
      bgart.width = 0;
    }
But it didn't work: "bgart.height" actually returns 0 instead of the actual scaled height, so the test is always true and it always scales to the height.

So is there a way to check the dimension of an artwork?
Title: Re: How to check the width/height of artwork
Post by: akafox on August 07, 2020, 05:18:03 PM
You might get a better/faster reply posting this in the themes section.

I take it you know how to see the Height and Width of a picture in photoshop/gimp right?
Title: Re: How to check the width/height of artwork
Post by: walknight on August 07, 2020, 05:35:32 PM
I take it you know how to see the Height and Width of a picture in photoshop/gimp right?

Yes apparently  :). I could always crop them beforehand, but seeing AM with such powerful scripting support, I think it should be possible for AM to "auto-fit" the image?

I also wish to be able to "auto-pan" the image if it's a large one. I wrote some custom code to do that for another frontend I was using and it looked great.
Title: Re: How to check the width/height of artwork
Post by: progets on August 07, 2020, 06:18:39 PM
Check out the builtin modules. You might find preserve-art.nut and pan-and-scan.nut helpful.
Title: Re: How to check the width/height of artwork
Post by: walknight on August 07, 2020, 10:21:55 PM
Check out the builtin modules. You might find preserve-art.nut and pan-and-scan.nut helpful.

Yes Oomek on discord also mentioned them. Turns out to be exactly what I need!
Thanks!