Full-featured JIT resizing utility for Symphony CMS
By The Workers London Ltd.
Magical image resizer and tag generator, with fallback to DummyImage generator.
upload
: takes an xPath of Symphony’s <upload>
nodeupload
is omitted, it will generate a dummy image with the specified dimensions (w
and h
dimensions required in that case)'w'
: the requested width'h'
: the requested height (both can be set)<img/>
attributes. class
, id
, title
, name
, longdesc
, etc.)value-only
: if set to either 'w'
or 'h'
will return only the result number not the whole <img/>
tag.mode
: 'normal'
, 'fit'
, 'max'
'w'
, 'h'
, 'w'
and 'h'
'w'
and 'h'
'w'
, 'h'
, 'w'
and 'h'
h
and/or w
is passed and scales the specified dimensions to whatever value was passed.w
or h
are passed, then the missing value is derived proportionally. If both values are passed then both are applied, effectively constraining the image to a specified size.JITmode
: JIT modes (see docs on Symphony-CMS.com) JITcenter
: JIT center 1
to 9
JITexternal
: 0
or url
(without the http://
part)No explicit size = original size
<xsl:call-template name="img">
<xsl:with-param name="upload" select="$upload"></xsl:with-param>
</xsl:call-template>
Specifying both dimensions, using no explicit mode, will output exactly what you asked for.
<xsl:call-template name="img">
<xsl:with-param name="upload" select="$upload"></xsl:with-param>
<xsl:with-param name="w" select="300"></xsl:with-param>
<xsl:with-param name="h" select="200"></xsl:with-param>
</xsl:call-template>
To trigger this simply omit one dimension
<xsl:call-template name="img">
<xsl:with-param name="upload" select="$upload"></xsl:with-param>
<xsl:with-param name="w" select="300"></xsl:with-param>
</xsl:call-template>
This is useful if you want to proportinally constrain your images to set dimensions.
<xsl:call-template name="img">
<xsl:with-param name="upload" select="$upload"></xsl:with-param>
<xsl:with-param name="mode" select="'fit'"></xsl:with-param>
<xsl:with-param name="w" select="400"></xsl:with-param>
<xsl:with-param name="h" select="400"></xsl:with-param>
</xsl:call-template>
Makes sure that any automatically calculated value will be a (nearest neighbor) multiple of the grid you set.
<xsl:call-template name="img">
<xsl:with-param name="upload" select="$upload"></xsl:with-param>
<xsl:with-param name="mode" select="'trim'"></xsl:with-param>
<xsl:with-param name="gridsize" select="50"></xsl:with-param><!-- This will set a 50px grid -->
<xsl:with-param name="w" select="400"></xsl:with-param>
<!-- i.e.: 'h' will be trimmed to the nearest neighbor grid -->
</xsl:call-template>
Straighforward. W and H values are used as multiplier in this case.
<xsl:call-template name="img">
<xsl:with-param name="upload" select="$upload"></xsl:with-param>
<xsl:with-param name="gridsize" select="50"></xsl:with-param><!-- This will set a 50px grid -->
<xsl:with-param name="w" select="3"></xsl:with-param> <!-- When in 'pure' grid mode, these values act as multipliers -->
<xsl:with-param name="h" select="2"></xsl:with-param>
</xsl:call-template>
w and h needed as we don’t have XML metadata on the fetched image
<xsl:call-template name="img">
<xsl:with-param name="upload" select="'images.apple.com/home/images/mbp_hero20110224.png'"></xsl:with-param>
<xsl:with-param name="w" select="400"></xsl:with-param>
<xsl:with-param name="h" select="200"></xsl:with-param>
</xsl:call-template>
Note that we are not passing any upload param in this case.
<xsl:call-template name="img">
<xsl:with-param name="w" select="200"></xsl:with-param>
<xsl:with-param name="h" select="150"></xsl:with-param>
</xsl:call-template>
<xsl:apply-templates match="upload">
<xsl:with-param name="w" select="300"></xsl:with-param>
</xsl:apply-templates>
<xsl:call-template name="img">
<xsl:with-param name="upload" select="$upload"></xsl:with-param>
<xsl:with-param name="w" select="500"></xsl:with-param>
<xsl:with-param name="class" select="'someclass anotherclass'"></xsl:with-param>
<xsl:with-param name="id" select="'myID'"></xsl:with-param>
<xsl:with-param name="title" select="'Herr Title'"></xsl:with-param>
</xsl:call-template>
When this template is used as a match rather than called by name, the DummyImage mode is effectively inaccessible.
Besides, it wouldn’t make sense since you if have a match, then you have an upload.
By The Workers London Ltd. theworkers.net - io@theworkers.net