Canvas

class Canvas

Server-side drawing interface geared towards customizing card art for issued credentials.

Drawing methods have config argument that provides drawing parameters in JSON format. The following properties are common for all operations (0 is default value for all of them):

  • x - horizontal position for the drawing

  • y - vertical position for the drawing

  • rotate - rotation in degrees clockwise around the drawing position

Also drawText and drawRect take an array of effects, where each element of the array is an object. The type of the effect is selected using type value. The following types are supported (and their parameters):

  • fill - fills the object with an ARGB color

    • argb - 8-digit hex string that defines the color (white is default)

  • blur - fills the object with an ARGB color and blurs the result using Gaussian blur

    • argb - 8-digit hex string that defines the color (black is default)

    • radius - Gaussian blur radius (2 is default)

    • dx - additional horizontal shift (0 is default)

    • dy - additional vertical shift (0 is default)

  • lighting - draw the object using the given color; then using only object's opacity map as a starting point, blur it using given radius and use the result as an elevation map to calculate lighting using a single distant light source

    • argb - 8-digit hex string that defines the color ("FFC0C0C0" is default)

    • light_rgb - 6-digit hex string that defines light source RGB color (white is default)

    • amplitude - strength of the lighting effect (1 is default)

    • surface_scale - scale of the elevation map (1.5 is default)

    • azimuth - azimuth angle of the lighting source in degrees (140 is default)

    • elevation - elevation angle of the lighting source in degrees (30 is default)

    • specular_exponent - directional density of the lighting source (13 is default)

    • blur_radius - radius of the opacity map blurring

Specific details on the lighting and blurring can be found in W3C SVG 1.1 Specification.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
val height: Int

Height of the canvas in pixels.

Link copied to clipboard
val width: Int

Width of the canvas in pixels.

Functions

Link copied to clipboard
suspend fun drawImage(name: String, config: JsonObject)

Draws the image, loading it using the resource name.

fun drawImage(bytes: ByteString, config: JsonObject)

Draw the image encoded in the given ByteString.

Link copied to clipboard
fun drawRect(config: JsonObject)

Draws the rectangle.

Link copied to clipboard
suspend fun drawText(text: String, config: JsonObject)

Draws text.

Link copied to clipboard

Returns data url that represents the canvas content.

Link copied to clipboard

Returns pixel array (as premultiplied ARGB colors packed in integers) that represents the canvas content.

Link copied to clipboard

Returns PNG image that represents the canvas content.