GithubHelp home page GithubHelp logo

wesbos / deno-canvas Goto Github PK

View Code? Open in Web Editor NEW

This project forked from djdeveloperr/deno-canvas

1.0 1.0 0.0 22.08 MB

Canvas API for Deno, ported from canvaskit-wasm (Skia).

Home Page: https://deno.land/x/canvas

License: MIT License

JavaScript 62.37% TypeScript 37.63%

deno-canvas's Introduction

deno-canvas

Canvas API for Deno, ported from canvaskit-wasm (Skia).

Installation

Import from https://deno.land/x/canvas/mod.ts or just import from raw GitHub URL, https://raw.githubusercontent.com/DjDeveloperr/deno-canvas/master/mod.ts.

Usage

mod.ts provides a default export exposing the complete CanvasKit API, and other exports from the file are types and utility functions.

import { createCanvas } from "https://deno.land/x/canvas/mod.ts";

const canvas = createCanvas(200, 200);
const ctx = canvas.getContext("2d");

ctx.fillStyle = "red";
ctx.fillRect(10, 10, 200 - 20, 200 - 20);

await Deno.writeFile("image.png", canvas.toBuffer());

And run with deno run --allow-write filename.ts.

You can also try this HTTP server example, https://raw.githubusercontent.com/DjDeveloperr/deno-canvas/master/examples/square.ts

For using images, use loadImage method exported from mod.ts.

const image = await loadImage(myURL);
ctx.drawImage(image, x, y);

Limitations

Just like original canvaskit-wasm, the emulated Canvas has some limitations:

  • measureText returns width only and does no shaping. It is only sort of valid with ASCII letters.
  • textAlign is not supported.
  • textBaseAlign is not supported.
  • fillText does not support the width parameter.

Alternative

There is also skia_canvas.

  • Fast & low-overhead, 2x performance improvement
  • Above mentioned limitations are not present, in fact there are no limitations
  • Uses FFI instead of WASM

License

Check LICENSE for more info.

Copyright 2022 © DjDeveloperr

deno-canvas's People

Contributors

djdeveloperr avatar konsumer avatar kt3k avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.