Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 Today 06:40:02

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,649
Website

Checking portrait/landscape mode for images

For a shortcode, I am trying to check if an image is in portrait mode (width < height) or landscape (w >= h), landscape can include square image. I can easily set up a variable to calculate the ratio, untested :-):

<txp:variable value='<txp:evaluate query="<txp:image_info type="w"/>/<txp:image_info type="h"/>" />" name="aspect-ratio" />

But then I am stuck – how to use that output? Thinking that <txp:evaluate query="……"/> would the way. The docs suggests using XPath functions, but I have no idea what would do.

In pseudo code: if output of the variable is <1 then use the portrait code, otherwise the landscape code path.

That code path would include both thumbnail-generation values and some class="" for layout purposes.

Or if there is another way, I am all ears!

TY.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg

Offline

#2 Today 07:04:49

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,204
Website GitHub

Re: Checking portrait/landscape mode for images

You’re pretty much there with a few changes to your quoting and div rather than /:

<txp:variable value='<txp:evaluate query=''<txp:image_info type="w"/> div <txp:image_info type="h"/>'' />' name="aspect-ratio" />

<txp:evaluate query='<txp:variable name="aspect-ratio" /> > 1'>
    Landscape
<txp:else />
    Portrait
</txp:evaluate>

Use >= to include square format as landscape (or <1 as you suggested and turn around the logic).

You can do it in one step without the variable, too:

<txp:evaluate query='(<txp:image_info type="w"/> div <txp:image_info type="h"/>) > 1'>
    Landscape
<txp:else />
    Portrait
</txp:evaluate>

TXP Builders – finely-crafted code, design and txp

Offline

#3 Today 12:37:05

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,649
Website

Re: Checking portrait/landscape mode for images

Thank you Jakob. That second variant is very interesting. I need to learn more about those mathematical queries.

Will play with those soon.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg

Offline

Board footer

Powered by FluxBB