Difference between revisions of "Getdim"
From Sega Retro
(future replacement for w2h/h2w/d2w templates) |
|||
Line 1: | Line 1: | ||
− | <includeonly>{{#vardefine:actuald|{{#replace:{{{actual|}}}|×|x}}}}{{#vardefine:actualw|{{#explode:{{#var:actuald}}|x|0}}}}{{#vardefine:actualh|{{#explode:{{#var:actuald}}|x|1}}}}{{#vardefine:scalew|{{#expr:{{{w|{{#var:actualw}}}}} div {{#var:actualw}} }}}}{{#vardefine:scaleh|{{#expr:{{{h|{{#var:actualh}}}}} div {{#var:actualh}} }}}}{{#vardefine:scalef|{{#ifexpr:{{#var:scalew}}<{{#var:scaleh}}|{{#var:scalew}}|{{#var:scaleh}}}}}}{{#vardefine:outputf|{{#switch:{{{output|}}} | + | <includeonly>{{#vardefine:actuald|{{#replace:{{#if:{{{file|}}}|{{#mediadimensions:{{{file|}}}}}|{{{actual|}}}}}|×|x}}}}{{#vardefine:actualw|{{#explode:{{#var:actuald}}|x|0}}}}{{#vardefine:actualh|{{#explode:{{#var:actuald}}|x|1}}}}{{#vardefine:scalew|{{#expr:{{{w|{{#var:actualw}}}}} div {{#var:actualw}} }}}}{{#vardefine:scaleh|{{#expr:{{{h|{{#var:actualh}}}}} div {{#var:actualh}} }}}}{{#vardefine:scalef|{{#ifexpr:{{#var:scalew}}<{{#var:scaleh}}|{{#var:scalew}}|{{#var:scaleh}}}}}}{{#vardefine:outputf|{{#switch:{{{output|}}} |
| w={{#expr:floor({{#var:scalef}}*{{#var:actualw}})}} | | w={{#expr:floor({{#var:scalef}}*{{#var:actualw}})}} | ||
| h={{#expr:floor({{#var:scalef}}*{{#var:actualh}})}} | | h={{#expr:floor({{#var:scalef}}*{{#var:actualh}})}} | ||
Line 19: | Line 19: | ||
<pre>{{getdim|actual={{#mediadimensions:Sonic1 title.png}}|w=160|h=1000|output=w|var=sanic}}{{#var:sanic}}</pre> | <pre>{{getdim|actual={{#mediadimensions:Sonic1 title.png}}|w=160|h=1000|output=w|var=sanic}}{{#var:sanic}}</pre> | ||
returns: {{getdim|actual={{#mediadimensions:Sonic1 title.png}}|w=160|h=1000|output=w|var=sanic}}{{#var:sanic}} | returns: {{getdim|actual={{#mediadimensions:Sonic1 title.png}}|w=160|h=1000|output=w|var=sanic}}{{#var:sanic}} | ||
+ | |||
+ | |||
+ | <pre>{{getdim|file=Sonic1 title.png|w=1000|h=112|output=w}}</pre> | ||
+ | returns: {{getdim|file=Sonic1 title.png|w=1000|h=112|output=w}} | ||
[[Category:Sega Retro templates]]</noinclude> | [[Category:Sega Retro templates]]</noinclude> |
Revision as of 12:12, 9 December 2019
This template obtains the width or height of a resized image, given the real dimensions of that image.
Usage
{{getdim|actual=320x224|w=160|output=h}}
returns: 112
{{getdim|actual=320x224|h=112|output=w}}
returns: 160
{{getdim|actual=320x224|h=112|w=1000|output=w}}
returns: 160
{{getdim|actual={{#mediadimensions:Sonic1 title.png}}|w=160|h=1000|output=w|var=sanic}}{{#var:sanic}}
returns: 160
{{getdim|file=Sonic1 title.png|w=1000|h=112|output=w}}
returns: 160