html2canvas图片的文字偏移,html2canvas html截图插件图片放大清晰度解决方案,支持任意放大倍数,解决原插件图片偏移问题...

本文介绍了如何解决html2canvas在截图时出现的文字偏移和图片放大模糊的问题,通过修改插件源码并提供自定义放大倍数支持,确保截图清晰度。
摘要由CSDN通过智能技术生成

html2canvas html截图插件图片放大清晰度解决方案,支持任意放大倍数,解决原插件图片偏移问题

Author:youzebin (2016.12.6)

插件下载地址:https://github.com/niklasvh/h…

1.首先引入html2canvas.js html2canvas 0.5.0-beta4 最新版即可

必要步骤1:修改插件的源码: (修改的地方有两处)

1. 代码第 999 行 renderWindow 的方法中 修改判断条件 增加一个options.scale存在的条件:

源码:

if (options.type === "view") {

canvas = crop(renderer.canvas, {width: renderer.canvas.width, height: renderer.canvas.height, top: 0, left: 0, x: 0, y: 0});

} else if (node === clonedWindow.document.body || node === clonedWindow.document.documentElement || options.canvas != null) {

canvas = renderer.canvas;

} else {

canvas = crop(renderer.canvas, {width: options.width != null ? options.width : bounds.width, height: options.height != null ? options.height : bounds.height, top: bounds.top, left: bounds.left, x: 0, y: 0});

}

改为:

if (options.type === "view") {

canvas = crop(renderer.canvas, {width: renderer.canvas.width, height: renderer.canvas.height, top: 0, left: 0, x: 0, y: 0});

} else if (node === clonedWindow.document.body || node === clonedWindow.document.documentElement) {

canvas = renderer.canvas;

}else if(options.scale && options.canvas !=null){

log("放大canvas",options.canvas);

var scale = options.scale || 1;

canvas = crop(renderer.canvas, {width: bounds.width * scale, height:bounds.height * scale, top: bounds.top *scale, left: bounds.left *scale, x: 0, y: 0});

}

else {

canvas = crop(renderer.canvas, {width: options.width != null ? options.width : bounds.width

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值