-
Notifications
You must be signed in to change notification settings - Fork 1
/
aspect-ratio-calculator.xsl
47 lines (31 loc) · 1.1 KB
/
aspect-ratio-calculator.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
Aspect Ratio calculators
@package Utility Monkey
@author John Porter <john@designermonkey.co.uk>
@license CC0 <http://creativecommons.org/publicdomain/zero/1.0/>
-->
<!--
Aspect Ratio by Width
Given a width, height and output width, define the correct output height
-->
<xsl:template name="aspect-ratio-by-width">
<xsl:param name="input-width"/>
<xsl:param name="input-height"/>
<xsl:param name="output-width"/>
<xsl:variable name="ratio" select="$input-height div $input-width"/>
<xsl:value-of select="ceiling($output-width * $ratio)"/>
</xsl:template>
<!--
Aspect Ration by Height
Given a width, height and output height, define the correct output width
-->
<xsl:template name="aspect-ratio-by-height">
<xsl:param name="input-width"/>
<xsl:param name="input-height"/>
<xsl:param name="output-height"/>
<xsl:variable name="ratio" select="$input-height div $input-width"/>
<xsl:value-of select="ceiling($output-height div $ratio)"/>
</xsl:template>
</xsl:stylesheet>