← all modules

Std.Image.Canvas

Std.Image.Canvas
  Std.Image.Canvas — draw an image on the server: shapes, text, pasted

Types
  type Canvas
  type alias Rgba = { red : Int , green : Int , blue : Int , alpha : Int }
  type Paint = Fill Rgba | Stroke Int Rgba
  type Mask
  type Filter = Nearest | Bilinear | CatmullRom | Lanczos
  type Font
  type alias TextStyle = { font : Font , size : Float , colour : Rgba }

Values
  alphaMask : String -> Mask
      A mask from an image: its alpha channel when it has transparency, else
  arc : Int -> Int -> Int -> Float -> Float -> Paint -> Canvas -> Canvas
      Part of a circle: `arc centreX centreY radius startDegrees endDegrees
  blank : Int -> Int -> Rgba -> Canvas
      A blank canvas of `width` x `height` in one colour (`rgba 0 0 0 0` for a
  blur : Float -> Canvas -> Canvas
      Blur the whole canvas: a Gaussian blur of `sigma` pixels (three box
  defaultFont : Font
      Go Regular, a sans-serif font built into Sky (BSD licence). It needs no
  ellipse : Int -> Int -> Int -> Int -> Paint -> Canvas -> Canvas
      The ellipse inside a box: `ellipse x y width height paint`. A square box
  ellipseMask : Int -> Int -> Mask
      The ellipse inside `width` x `height` (a round avatar).
  encode : Image.Format -> Canvas -> Task Error String
      Draw every step and write the image in a `Std.Image.Format`. `Preserve`
  fontFromBytes : String -> Int -> Result Error Font
      A font from its bytes (`index` as for `loadFont`).
  fromImage : String -> Canvas
      A canvas that starts as an image (JPEG, PNG, GIF, WebP), the size of the
  line : Int -> Int -> Int -> Int -> Int -> Rgba -> Canvas -> Canvas
      A straight line between two pixels: `line x1 y1 x2 y2 width colour`.
  loadFont : String -> Int -> Task Error Font
      Read a TrueType or OpenType font file. `index` picks a font in a `.ttc`
  measure : Font -> Float -> String -> { width : Int, height : Int, ascent : Int, descent : Int }
      The size of a text in whole pixels (rounded up): the widest line's
  paste : Int -> Int -> Maybe Mask -> String -> Canvas -> Canvas
      Paste an image (its bytes) with its top-left corner at `x`, `y`, over
  pasteCanvas : Int -> Int -> Maybe Mask -> Canvas -> Canvas -> Canvas
      Paste another canvas, as `paste` does.
  pasteExact : Int -> Int -> String -> Canvas -> Canvas
      Put an image (its bytes) with its top-left corner at `x`, `y` IN PLACE OF
  pixelDiff : Int -> String -> String -> Task Error Int
      The number of pixels where two images differ: a pixel counts when its
  rect : Int -> Int -> Int -> Int -> Paint -> Canvas -> Canvas
      A rectangle: `rect x y width height paint`.
  resize : Filter -> Int -> Int -> Canvas -> Canvas
      Scale the canvas to exactly `width` x `height` (the steps after it draw
  rgba : Int -> Int -> Int -> Int -> Rgba
      `rgba red green blue alpha`.
  roundedMask : Int -> Int -> Int -> Mask
      A rectangle of `width` x `height` with round corners of `radius` (an
  roundedRect : Int -> Int -> Int -> Int -> Int -> Paint -> Canvas -> Canvas
      A rectangle with round corners of `radius` pixels:
  text : TextStyle -> Int -> Int -> String -> Canvas -> Canvas
      Write text with the left edge of its first line at `x` and the top of