Skip to content

Commit

Permalink
saveSVG() logo image can not show bug fixed.
Browse files Browse the repository at this point in the history
saveSVG() logo image can not show bug fixed.
  • Loading branch information
ushelp committed Jul 23, 2021
1 parent 7831b7e commit 4ab2d88
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 611 deletions.
7 changes: 4 additions & 3 deletions canvas2svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,6 @@
* http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-context-2d-drawimage
*/
ctx.prototype.drawImage = function() {

//convert arguments to a real array
var args = Array.prototype.slice.call(arguments),
image = args[0],
Expand Down Expand Up @@ -1226,18 +1225,20 @@
svgImage.setAttribute("height", dh);
svgImage.setAttribute("preserveAspectRatio", "none");
svgImage.setAttribute("opacity", this.globalAlpha);

if (sx || sy || sw !== image.width || sh !== image.height) {
//crop the image using a temporary canvas
canvas = this.__document.createElement("canvas");
canvas.width = dw;
canvas.height = dh;
context = canvas.getContext("2d");
context.drawImage(image, sx, sy, sw, sh, 0, 0, dw, dh);
context.drawImage(t, sx, sy, sw, sh, 0, 0, dw, dh);
image = canvas;
}

svgImage.setAttribute("transform", translateDirective);
svgImage.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href",
image.nodeName === "CANVAS" ? image.toDataURL() : image.src);
image.nodeName === "CANVAS" ? image.toDataURL() : image.originalSrc);
parent.appendChild(svgImage);
};

Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* NodeJS QRCode generator. Can save image or svg to file, get standard base64 image data url text or get SVG serialized text. Cross-browser QRCode generator for pure javascript. Support Dot style, Logo, Background image, Colorful, Title etc. settings. support binary mode.(Running without DOM on server side)
*
* Version 4.3.3
* Version 4.3.4
*
* @author [ inthinkcolor@gmail.com ]
*
Expand Down Expand Up @@ -1209,6 +1209,7 @@ Drawing.prototype.draw = function(oQRCode) {
bgImg.onerror = function(e) {
t.reject(e);
}
bgImg.originalSrc = _htOption.backgroundImage;
bgImg.src = _htOption.backgroundImage;
// DoSomething
} else {
Expand Down Expand Up @@ -1460,6 +1461,7 @@ Drawing.prototype.draw = function(oQRCode) {
// console.error(e);
t.reject(e);
}
img.originalSrc=_htOption.logo;
img.src = _htOption.logo;
// if (img.complete) {
// img.onload = null;
Expand Down
4 changes: 2 additions & 2 deletions index.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 4ab2d88

Please sign in to comment.