A collection of functions for working with images. Internally, these make use of the sharp image library.
dimensions(buffer) #
Returns the height and width of the image in pixels.
$ ori Origami.image.dimensions image.jpeg
height: 1500
width: 2000
One use for this is to add explicit height and width attributes to an <img> tag:
// imageDimensions.ori
(buffer, name) =>
Origami.image.dimensions(buffer)
-> (dimensions) => Tree.indent`
<img src="${ name }" height="${ dimensions.height }" width="${ dimensions.width }">
`
This template uses Origami.image.dimensions to obtain the height and width, then incorporates those as attributes on an <img> tag:
$ ori imageDimensions.ori image.jpeg, «image.jpeg»
<img src="image.jpeg" height="1500" width="2000">
format(buffer, format, [options]) #
Returns the image represented by buffer in a new image format. The format must be one of the following strings:
avifgifheifjp2jpegjxlpngrawtifftilewebp
The options dictionary is passed to sharp’s toFormat() function.
Example: to convert a file image.jpeg to WebP format:
$ ori "Origami.image.format(image.jpeg, 'webp')"
resize(buffer, options) #
Returns a new image, resizing the image represented by buffer. The options should include a height and/or width property.