Skip to content

Canvas

Canvas

Canvas(width: int, height: int, dpi: float)

A Canvas is a two-dimensional drawing area of size width × height pixels using the specified dpi (dots per inch).

Info
  • A canvas uses a standard color space with at least 8 bits per channel.
  • Blending mode is alpha blending
  • The (0,0) coordinates corresponds to the bottom left corner.
  • A typographical point is 1/72 inch.
Example
from gsp.core.canvas import Canvas
canvas = Canvas(512, 512, 101.0)
1. COMMAND
     - METHOD: "core.Canvas" (str)
     - COMMAND_ID: 1 (int)
     - TIMESTAMP: 2024-08-21T12:52:32.533071 (datetime)
   PARAMETERS
     - OBJECT_ID: 1 (int)
     - WIDTH: 512 (int)
     - HEIGHT: 512 (int)
     - DPI: 101.0 (float)

{
  "jsonrpc": "2.0",
  "commands": [
    {
      "method": "core.Canvas",
      "id": 1,
      "timestamp": 1724237552.533071,
      "parameters": {
        "id": 1,
        "width": 512,
        "height": 512,
        "dpi": 101.0
      }
    }
  ]
}

Create a new Canvas

Parameters:

Name Type Description Default
width int

Width of the drawing area in pixels.

required
height int

Height of the drawing area in pixels.

required
dpi float

Dots per inch

required

render

render(target: str)

Render the canvas the to specified target. If no target is specified, return a raw image as bytes.

Example
1
2
3
from gsp.core.canvas import Canvas
canvas = Canvas(512, 512, 100.0)
canvas.render("png")
1. COMMAND
     - METHOD: "core.Canvas" (str)
     - COMMAND_ID: 1 (int)
     - TIMESTAMP: 2024-08-21T12:52:32.602260 (datetime)
   PARAMETERS
     - OBJECT_ID: 1 (int)
     - WIDTH: 512 (int)
     - HEIGHT: 512 (int)
     - DPI: 100.0 (float)

2. COMMAND
     - METHOD: "Canvas/render" (str)
     - COMMAND_ID: 2 (int)
     - TIMESTAMP: 2024-08-21T12:52:32.602297 (datetime)
   PARAMETERS
     - OBJECT_ID: 1 (int)
     - TARGET: png (str)

{
  "jsonrpc": "2.0",
  "commands": [
    {
      "method": "core.Canvas",
      "id": 1,
      "timestamp": 1724237552.60226,
      "parameters": {
        "id": 1,
        "width": 512,
        "height": 512,
        "dpi": 100.0
      }
    },
    {
      "method": "Canvas/render",
      "id": 2,
      "timestamp": 1724237552.602297,
      "parameters": {
        "id": 1,
        "target": "png"
      }
    }
  ]
}

Parameters:

Name Type Description Default
target str

Filename of the target

required