Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update dom to image to pgn #471

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/dom-to-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@
* @param {Boolean} options.cacheBust - set to true to cache bust by appending the time to the request url
* @return {Promise} - A promise that is fulfilled with a SVG image data URL
* */
function toSvg(node, options) {
function toSvg(node, options, loadfonts) {
options = options || {};
copyOptions(options);
return Promise.resolve(node)
.then(function (node) {
return cloneNode(node, options.filter, true);
})
.then(embedFonts)
.then(loadfonts && embedFonts)
.then(inlineImages)
.then(applyOptions)
.then(function (clone) {
Expand Down Expand Up @@ -88,7 +88,7 @@
* @return {Promise} - A promise that is fulfilled with a Uint8Array containing RGBA pixel data.
* */
function toPixelData(node, options) {
return draw(node, options || {})
return draw(node, options || {},loadfonts || true)
.then(function (canvas) {
return canvas.getContext('2d').getImageData(
0,
Expand All @@ -104,8 +104,8 @@
* @param {Object} options - Rendering options, @see {@link toSvg}
* @return {Promise} - A promise that is fulfilled with a PNG image data URL
* */
function toPng(node, options) {
return draw(node, options || {})
function toPng(node, options, loadfonts) {
return draw(node, options || {}, loadfonts || true)
.then(function (canvas) {
return canvas.toDataURL();
});
Expand All @@ -118,7 +118,7 @@
* */
function toJpeg(node, options) {
options = options || {};
return draw(node, options)
return draw(node, options,loadfonts || true)
.then(function (canvas) {
return canvas.toDataURL('image/jpeg', options.quality || 1.0);
});
Expand All @@ -130,7 +130,7 @@
* @return {Promise} - A promise that is fulfilled with a PNG image blob
* */
function toBlob(node, options) {
return draw(node, options || {})
return draw(node, options || {},loadfonts || true)
.then(util.canvasToBlob);
}

Expand All @@ -149,8 +149,8 @@
}
}

function draw(domNode, options) {
return toSvg(domNode, options)
function draw(domNode, options, loadfonts) {
return toSvg(domNode, options, loadfonts)
.then(util.makeImage)
.then(util.delay(100))
.then(function (image) {
Expand Down