Skip to content

Commit 4ab2d88

Browse files
committed
saveSVG() logo image can not show bug fixed.
saveSVG() logo image can not show bug fixed.
1 parent 7831b7e commit 4ab2d88

File tree

5 files changed

+277
-611
lines changed

5 files changed

+277
-611
lines changed

canvas2svg.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,6 @@
11811181
* http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-context-2d-drawimage
11821182
*/
11831183
ctx.prototype.drawImage = function() {
1184-
11851184
//convert arguments to a real array
11861185
var args = Array.prototype.slice.call(arguments),
11871186
image = args[0],
@@ -1226,18 +1225,20 @@
12261225
svgImage.setAttribute("height", dh);
12271226
svgImage.setAttribute("preserveAspectRatio", "none");
12281227
svgImage.setAttribute("opacity", this.globalAlpha);
1228+
12291229
if (sx || sy || sw !== image.width || sh !== image.height) {
12301230
//crop the image using a temporary canvas
12311231
canvas = this.__document.createElement("canvas");
12321232
canvas.width = dw;
12331233
canvas.height = dh;
12341234
context = canvas.getContext("2d");
1235-
context.drawImage(image, sx, sy, sw, sh, 0, 0, dw, dh);
1235+
context.drawImage(t, sx, sy, sw, sh, 0, 0, dw, dh);
12361236
image = canvas;
12371237
}
1238+
12381239
svgImage.setAttribute("transform", translateDirective);
12391240
svgImage.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href",
1240-
image.nodeName === "CANVAS" ? image.toDataURL() : image.src);
1241+
image.nodeName === "CANVAS" ? image.toDataURL() : image.originalSrc);
12411242
parent.appendChild(svgImage);
12421243
};
12431244

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* 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)
55
*
6-
* Version 4.3.3
6+
* Version 4.3.4
77
*
88
* @author [ [email protected] ]
99
*
@@ -1209,6 +1209,7 @@ Drawing.prototype.draw = function(oQRCode) {
12091209
bgImg.onerror = function(e) {
12101210
t.reject(e);
12111211
}
1212+
bgImg.originalSrc = _htOption.backgroundImage;
12121213
bgImg.src = _htOption.backgroundImage;
12131214
// DoSomething
12141215
} else {
@@ -1460,6 +1461,7 @@ Drawing.prototype.draw = function(oQRCode) {
14601461
// console.error(e);
14611462
t.reject(e);
14621463
}
1464+
img.originalSrc=_htOption.logo;
14631465
img.src = _htOption.logo;
14641466
// if (img.complete) {
14651467
// img.onload = null;

index.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)