API quickstart#
API hub · Quickstart · Cheatsheet
The whole API in five steps: install, draw a script from the command line, draw it from Node, build a graphic in code, and link a logo.
The whole thing in five steps#
- Install the command line, which puts
napkin-sketchon your PATH, and the API in a folder of your own:
npm install -g @isocialpractice/napkin-sketch
npm install @isocialpractice/napkin-sketch
From a clone, npm install, npm run build and npm link do the same, and
the files below go in the clone.
- Save this as
card.napkinin that folder, and draw it from the command line:
napkin 1
page 400 300
name "card"
layer "Card"
color #1f2328 width 3 fill #ffe08a
rect 20 20 360 260 r 16
text "Acme Corp" at 200 120 size 32 align center
napkin-sketch draw card.napkin --to svg,png,pdf --out out
- Draw the same script from Node. Save this as
draw.mjsand runnode draw.mjs:
import { drawFile } from '@isocialpractice/napkin-sketch/node';
const { ok, files, diagnostics } = await drawFile('card.napkin', { out: 'out', formats: ['svg', 'png'] });
console.log(ok, files.map((file) => file.path), diagnostics);
- Build a graphic in code instead. Save this as
badge.mjsand runnode badge.mjs:
import { writeFile } from 'node:fs/promises';
import { createComposition } from '@isocialpractice/napkin-sketch';
const design = createComposition({ width: 240, height: 240, background: '#ffffff' });
design.circle({ cx: 120, cy: 110, r: 80, fill: '#326478' });
design.text({ x: 120, y: 216, text: 'Acme Corp', align: 'center', fontSize: 20, fill: '#1f2328' });
await writeFile('badge.svg', design.toSVG());
await writeFile('badge.png', design.toPNG());
- Link a logo rather than import it. Save any SVG as
logo.svgbeside the script, add this line to the end ofcard.napkin, and draw again. The SVG keepshref="logo.svg", and the PNG draws the file:
link "logo.svg" at 290 220 size 80 40 name "Logo"
Where to go next#
- The napkin script language: a script that checks clean, as text and as JSON.
- Drawing with napkin script: shapes, paint, text and the hand-drawn pass.
- The graphic design API: gradients, masks and holes in code.
- Writing a drawing out: five formats, cut to the ink or a box.
- The napkin-sketch command line:
check,render,verbsand--json. - Using napkin-sketch from code: the two entries, and images passed in.
- Working with other programs: Illustrator, Inkscape, an Illustrator script, and linked files.
- The AI helpers: a design language and a skill from a graphic you have, and a script from a sentence.