-
Notifications
You must be signed in to change notification settings - Fork 15
scale2w
The "scale2w" Snippet is an output filter that operates on an asset ID and returns a URL to the image of the desired size. It scales the asset to a desired width and calculates the height to preserve the aspect ratio of the original image. This request will trigger the desired image size to be generated if it does not exist already.
Specify the desired width as an integer (in pixels).
Normally, the asset_id parameter would be supplied via the getPageAssets Snippet, so the following might be used inside a formatting Chunk where "asset_id" was available as a placeholder:
[[getPageAssets?
&innerTpl=`<img src="[[+asset_id:scale2w=`600`]]" width="600" height="[[+asset_id.height]]" />`
]]
The calculated width is available as a placeholder: [[+asset_id.width]]
Although unconventional, it is possible to call the scale2w Snippet as a stand-alone Snippet and not as an output filter. This is useful if you wanted to display a single asset at a desired size. In the example below, asset ID 123 will be resized to a width of 600.
<img src="[[scale2w? &input=`123` &options=`600`]]" width="600" height="[[+asset_id.height]]" />
Note that this usage would be equivalent to using the Asset Snippet:
[[Asset?
&asset_id=`123`
&width=`600`
&tpl=`<img src="[[+url]]" width="600" height="[[+asset_id.height]]"`
]]
© 2014 and beyond by Craftsman Coding