-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Background-Image not displayed after capture #185
Comments
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
+1, any workaround ? |
I had a similar problem with loading an img HTML tag. The problem was that the Image itself takes longer to generate then the actual DOM element. I fixed the problem after many tries with a Timeout before executing the domtoimage.toPng function. import { Component, OnInit, AfterViewInit, ViewChild, ElementRef } from '@angular/core'; export class EndpageComponent implements OnInit, AfterViewInit { domtoimage.toPng(node) }, 100); |
@Raven-T |
+1 |
1 similar comment
+1 |
+1, if set background with BASE64 type , it`s ok! But set background with imageURL were not OK. |
+1 |
doesnt seem to work properly. It worked a couple of times. However, doesnt render well on mobile and browsers other than Chrome. |
在我们的项目中使用了此插件(h5ds.com),最终我们将background图片修改成base64即可解决此问题,修改 大概600行方法:inlineAll function getBase64(src) {
console.log('urlurlurlurl', src);
return new Promise((resolve, reject) => {
var img = new Image();
img.crossOrigin = 'Anonymous'; // 允许跨域
img.onload = () => {
var width = img.naturalWidth;
var height = img.naturalHeight;
var canvas = $('<canvas width="' + width + '" height="' + height + '"></canvas>')[0];
var ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0, width, height, 0, 0, width, height);
resolve(canvas.toDataURL());
};
img.onerror = err => {
console.error('图片转base64失败!');
reject(err);
};
img.src = src;
});
}
async function inlineAll(string, baseUrl, get) {
if (nothingToInline()) return Promise.resolve(string);
// 背景图转化成base64解决浏览器不能截取的问题
var url = string.split(' ')[0];
if (url.indexOf('url(') !== -1) {
url = url.replace(/"|'|url|\(|\)/g, '');
var base64 = await getBase64(url + '?dom-to-image');
string = string.replace(url, base64);
}
return Promise.resolve(string)
.then(readUrls)
.then(function (urls) {
var done = Promise.resolve(string);
urls.forEach(function (url) {
if (!urlsCache[url]) {
done = done.then(function (string) {
return inline(string, url, baseUrl, get);
});
urlsCache[url] = done;
}
});
return done;
});
function nothingToInline() {
return !shouldProcess(string);
}
} |
+1 |
1 similar comment
+1 |
+1 not working for some image edit: |
+1 |
Expected behavior
When I capture div with background-image, display this image in the captured image
Actual behavior (stack traces, console logs etc)
No image is displayed, but the div contents displayed
Library version
2.6.0
Browsers
The text was updated successfully, but these errors were encountered: