-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8c344a
commit ad1ea43
Showing
2 changed files
with
35 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,33 @@ | ||
# deno-canvas | ||
# deno-canvas | ||
|
||
Canvas API for Deno, ported from [canvaskit-wasm (Skia)](https://github.com/google/skia/tree/master/modules/canvaskit). | ||
|
||
## Installation | ||
Just import from raw GitHub URL, https://raw.githubusercontent.com/DjDeveloperr/deno-canvas/master/mod.ts. I'll publish on deno.land soon. | ||
|
||
## Usage | ||
mod.ts provides a default export exposing the complete CanvasKit API, and other exports from the file are types and util functions. | ||
|
||
```ts | ||
import Canvas, { CanvasRenderingContext2D } from '../mod.ts' | ||
import { serve } from "https://deno.land/[email protected]/http/server.ts"; | ||
import { dataURLtoFile } from "../utils.ts"; | ||
|
||
const canvas = Canvas.MakeCanvas(200, 200); | ||
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D; | ||
|
||
ctx.fillStyle = 'red'; | ||
ctx.fillRect(10, 10, 200 - 20, 200 - 20); | ||
|
||
const data = dataURLtoFile(canvas.toDataURL()); | ||
|
||
const server = serve({ hostname: "0.0.0.0", port: 8080 }); | ||
console.log(`HTTP webserver running. Access it at: http://localhost:8080/`); | ||
|
||
for await (const request of server) { | ||
request.respond({ status: 200, body: data }); | ||
} | ||
``` | ||
|
||
And run with `deno run --allow-red --allow-read filename.ts`! | ||
Or you can directly run from URL, `https://raw.githubusercontent.com/DjDeveloperr/deno-canvas/master/examples/square.ts` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.