-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Clean up img.src= Fixes #945 - support img.src = <url> Fixes #807 - support for non-base64 `data:` URIs Fixes #1079 - ditto Closes #564 - it works, probably didn't pass a string or buffer Makes all examples and the README use onload, onerror. * image: throw if no onerror listener attached
- Loading branch information
Showing
7 changed files
with
142 additions
and
75 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
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 |
---|---|---|
@@ -1,14 +1,18 @@ | ||
var fs = require('fs') | ||
var path = require('path') | ||
var Canvas = require('..') | ||
const fs = require('fs') | ||
const path = require('path') | ||
const Canvas = require('..') | ||
|
||
var Image = Canvas.Image | ||
var canvas = Canvas.createCanvas(288, 288) | ||
var ctx = canvas.getContext('2d') | ||
const Image = Canvas.Image | ||
const canvas = Canvas.createCanvas(288, 288) | ||
const ctx = canvas.getContext('2d') | ||
|
||
var img = new Image() | ||
img.src = fs.readFileSync(path.join(__dirname, 'images', 'grayscaleImage.jpg')) | ||
const img = new Image() | ||
img.onload = () => { | ||
ctx.drawImage(img, 0, 0) | ||
canvas.createJPEGStream().pipe(fs.createWriteStream(path.join(__dirname, 'passedThroughGrayscale.jpg'))) | ||
} | ||
img.onerror = err => { | ||
throw err | ||
} | ||
|
||
ctx.drawImage(img, 0, 0) | ||
|
||
canvas.createJPEGStream().pipe(fs.createWriteStream(path.join(__dirname, 'passedThroughGrayscale.jpg'))) | ||
img.src = path.join(__dirname, 'images', 'grayscaleImage.jpg') |
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,18 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const Canvas = require('..') | ||
|
||
const Image = Canvas.Image | ||
const canvas = Canvas.createCanvas(200, 300) | ||
const ctx = canvas.getContext('2d') | ||
|
||
const img = new Image() | ||
img.onload = () => { | ||
ctx.drawImage(img, 0, 0) | ||
canvas.createPNGStream() | ||
.pipe(fs.createWriteStream(path.join(__dirname, 'image-src-url.png'))) | ||
} | ||
img.onerror = err => { | ||
console.log(err) | ||
} | ||
img.src = 'http://picsum.photos/200/300' |
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
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