-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): added NodeJS example
- Loading branch information
Showing
5 changed files
with
567 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const hashicon = require('../../dist/hashicon.cjs.js') | ||
const fs = require('fs'); | ||
const outputDir = __dirname + "/output"; | ||
const hashString = "test"; | ||
|
||
const { createCanvas } = require('canvas'); | ||
const canvas = hashicon(hashString, { createCanvas }); | ||
|
||
// Try canvas.toDataURL | ||
fs.writeFile( | ||
`${outputDir}/${hashString}.html`, | ||
`<img src="${canvas.toDataURL()}" />`, | ||
err => console.log(`HTML file ${err ? 'got error: ' + err : 'created'}`) | ||
); | ||
|
||
// Try canvas.createPNGStream | ||
const out = fs.createWriteStream(`${outputDir}/${hashString}.png`); | ||
const stream = canvas.createPNGStream(); | ||
stream.pipe(out); | ||
out.on('finish', () => console.log('PNG file created')); |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.html | ||
*.png |
Oops, something went wrong.