magic.lambda.image - Manipulating and creating images from Hyperlambda

The magic.lambda.image project contains image manipulation functions for Hyperlambda, allowing you to do basic manipulation of images, in addition to generating QR codes. More specifically this project contains the following slot.

Transforming images

All image transformation slots works similarly. They can either be given a string being the relative filename of the image you want to transform, or a stream from where to load the image. All transformation slots can also be given a [type] argument, which is how to return the image after the transformation is done. Supported types are as follows.

In addition you can provide a [dest] argument, which if specified, becomes the relative path of where to save the image after transformation has been applied. If not specified, the image will be returned as a stream to caller, otherwise the image will be saved to the specified file.

How to use [image.resize]

Resizing an image can be done as follows.


The above will resize the specified image to a width of 250 pixel, converting it to PNG, while keeping the aspect ratio by calculating the new height automatically. You can provide either of.

You can provide both of the above, but at least one of the above must be specified. If one of the values are ommitted, it will be calculated by keeping the aspect ratio of the image as is. The [type] argument is how to return the image after the transformation has been applied, and can be any of the supported types as specified above. Notice, the image might be stretched in one direction if you change the existing width and height ratio during the transformation.

How to use [image.crop]

To crop an image you specify the following arguments.

Notice, left + right must be smaller than the total width of the image, and top + bottom must be smaller than the total height of the image. All arguments are optional, allowing you to only crop an image at one side, such as for instance illustrated below.


How to use [image.convert]

To convert an image from for instance png to jpeg, you can use something such as follows.


The above keeps the image as is, except converts it from its existing format to a jpeg image.

How to use [image.generate-qr]

You can use the [image.generate-qr] slot to create a QR code. This slot returns the QR code as a MemoryStream, which allows you to return its output directly over the HTTP response object, which again will persist the QR code back as the response to the caller if you’re in a web project of some sort using Magic. The slot takes two arguments.

Below is an example of usage


After execution, the above invocation slot will contain a MemoryStream encapsulating your underlaying QR code. Below is an example QR code generated by the library.

QR Code

Project website for magic.lambda.hyperlambda

The source code for this repository can be found at, and you can provide feedback, provide bug reports, etc at the same place.

The projects is copyright of Aista, Ltd 2021 - 2023