html2canvas

Can html2canvas render svg in a page?

五迷三道 提交于 2019-12-01 03:34:39
I am using html2canvas to create a 'screenshot' of a HTML page that contains SVG. Everything looks good, except the element. I know that it should be possible to render SVG in Canvas; PhantomJS, fabric.js and CanVG do it. Is this something that html2canvas does not support? Or am I doing something wrong, and this should just work? If this has not been implemented, what is the best way to extend html2canvas (using canvg)? rakensi Capturing SVG images works by transforming them into canvas, using canvg . Include both javascript files as indicated on that page. Then the easiest way to do this is:

Html2Canvas Resize

拟墨画扇 提交于 2019-12-01 02:10:34
问题 I am using html2canvas in an effort to get a screenshot of a webpage and render it as a thumbnail (well, 400x300, not exactly a thumbnail). Based on the Screenshot console code, everything works great with the exception of the thumbnail part. How can I set the image size to 400x300? In firebug I locate the attribute as: <canvas style="width: 973px; height: 2184px;" width="973" height="2184"></canvas> . However, I cannot figure out in my code(below) or in the html2canvas.js where to hardcode

How to capture screenshot of parts of the client “desktop” using HTML/JavaScript ?

两盒软妹~` 提交于 2019-12-01 01:33:36
I know how to capture webpage, but I am asking to how capture desktop or another application in the desktop ? And if there is anyway to highlight parts of screen. Like how html2canvas does for webpages, can we do something for desktop applications using a browser app in HTML/JS ? Yes, it is possible! But as far as I know only for Firefox and Chrome (I used Chrome). Thanks to Screen Capturing and WebRTC. More info about WebRTC I used a library called RTCMultiConnection which is very easy to use, but you should be able to do that also without any use of a library. Here, just to give you a

How to capture screenshot of parts of the client “desktop” using HTML/JavaScript ?

ぐ巨炮叔叔 提交于 2019-11-30 20:15:44
问题 I know how to capture webpage, but I am asking to how capture desktop or another application in the desktop ? And if there is anyway to highlight parts of screen. Like how html2canvas does for webpages, can we do something for desktop applications using a browser app in HTML/JS ? 回答1: Yes, it is possible! But as far as I know only for Firefox and Chrome (I used Chrome). Thanks to Screen Capturing and WebRTC. More info about WebRTC I used a library called RTCMultiConnection which is very easy

Scale image before toDataURL - html2canvas

最后都变了- 提交于 2019-11-30 15:06:33
Before you tell me this is a duplicate question, know that I've searched through every single similar question and none of the answers in any of them are working for me. Im using html2canvas to grab a snapshot of a div, and what I need to do is scale it up to 750x1050 before saving it to a png via canvas.toDataURL() . The closest I got was with the following code. html2canvas(document.getElementById('div_id'), { onrendered: function(canvas) { var extra_canvas = document.createElement("canvas"); extra_canvas.setAttribute('width', 750); extra_canvas.setAttribute('height', 1050); var ctx = extra

Convert SVG to image in PNG

无人久伴 提交于 2019-11-30 09:54:13
问题 i am converting angular nvd3 chart to svg using html2canvas and canvg plugings but when i convert pie chart to png then i looks same as chart but when i convert line chart or area chart then its background goes to black and some circle drown on image. My code is var svgElements = $("#container").find('svg'); //replace all svgs with a temp canvas svgElements.each(function () { var canvas, xml; // canvg doesn't cope very well with em font sizes so find the calculated size in pixels and replace

html2canvas save image doesn't work

心已入冬 提交于 2019-11-30 04:07:21
I'm rendering a screenshot with html2canvas 0.4.0 and want to save it as image on my webserver. To do so, I've written the following function: JavaScript function screenShot(id) { html2canvas(id, { proxy: "https://html2canvas.appspot.com/query", onrendered: function(canvas) { $('body').append(canvas); // This works perfect... var img = canvas.toDataURL("image/png"); var output = img.replace(/^data:image\/(png|jpg);base64,/, ""); var Parameters = "image=" + output + "&filedir=" + cur_path; $.ajax({ type: "POST", url: "inc/saveJPG.php", data: Parameters, success : function(data) { console.log

html2canvas 生成的图片变模糊解决方案

最后都变了- 提交于 2019-11-29 21:46:54
需求: 背景图片和二维码还有用户微信头像生成一张图片,可供用户下载。打开页面的时候就是一张图可以保存,html2canvas插件即可实现效果,效果是实现了,但是很郁闷,图片模糊了。。。。 为什么会模糊? 网上介绍说明是: 原来浏览器的window变量中有一个devicePixelRatio的属性,该属性决定了浏览器会用几个像素点来渲染1个像素,举例来说,假设devicePixelRatio的值为2,一张100x100像素大小的图片,在retina屏幕下,会用2个像素点的宽度去渲染图片的1个像素点,因此该图片在retina屏幕上实际会占据200x200像素的空间,相当于图片被放大了一倍,因此图片会变得模糊。知道了这一点,这个问题也就能理解了。当浏览器去渲染canvas的时候,他会用2个像素点的宽度去渲染canvas,因此在大多数retina设备的浏览器中会出现绘制的图片或文字变模糊的情况。 解决方案 1.先获取设备的 PixelRatio ,可参考 hidpi-canvas 提供的方法 getPixelRatio. 2.将canvas的容器扩大 PixelRatio 倍,再将画布缩放,将图像放大 PixelRatio 倍。 部分代码 在项目中发现生成的图片还是有点糊,还真是怪了,再看了下DOM结构,背景图是放在body中的,那既然背景图还是糊,那改成图片。在DOM中放一个div

前端通过html2canvas打印echarts图表

心已入冬 提交于 2019-11-29 21:39:30
项目上需要实现导出和打印html,本来直接调用的window.print,结果发现echarts图表无法打印,会是空白的,网上搜索了一下,都是采用转换为64位编码,感觉比较麻烦,找到了另一种办法,利用html2canvas直接将页面转换为canvas,再打印canvas就行了。 代码 // 打印日报 $("#printall").on("click", function () { if (confirm("您确认打印该PDF文件吗?")) { // 先用html2canvas将页面整个转为一张截图,再打印,防止出现echarts无法打印 html2canvas(document.getElementById('monthlyReport')).then( function (canvas) { window.print(canvas); // 打印canvas } ); } }); 有个问题,尽管通过document.getElementById('monthlyReport')获取了对应的id,但是在打印时还是会打印当前页面的东西,有一部分不需要的东西也被打印了 如图: 打印的效果 所以需要将上面的部分隐藏,使用css的 media,可以自动在调用打印时隐藏,当然也可以通过js在打印前隐藏,打印后再show 代码 /* 打印时隐藏面包屑导航和按钮无需打印 */ @media

Scale image before toDataURL - html2canvas

巧了我就是萌 提交于 2019-11-29 20:33:12
问题 Before you tell me this is a duplicate question, know that I've searched through every single similar question and none of the answers in any of them are working for me. Im using html2canvas to grab a snapshot of a div, and what I need to do is scale it up to 750x1050 before saving it to a png via canvas.toDataURL() . The closest I got was with the following code. html2canvas(document.getElementById('div_id'), { onrendered: function(canvas) { var extra_canvas = document.createElement("canvas"