Author Topic: How to check the width/height of artwork  (Read 2183 times)

walknight

  • Full Member
  • ***
  • Posts: 25
    • View Profile
How to check the width/height of artwork
« 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?
« Last Edit: August 07, 2020, 05:10:55 PM by walknight »

akafox

  • Hero Member
  • *****
  • Posts: 985
    • View Profile
Re: How to check the width/height of artwork
« Reply #1 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?
People want life easy..then complain about it

walknight

  • Full Member
  • ***
  • Posts: 25
    • View Profile
Re: How to check the width/height of artwork
« Reply #2 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.

progets

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1271
    • View Profile
Re: How to check the width/height of artwork
« Reply #3 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.

walknight

  • Full Member
  • ***
  • Posts: 25
    • View Profile
Re: How to check the width/height of artwork
« Reply #4 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!