jq将html转换成图片,可将canvas图像导出为多种格式图片的jQuery插件

ExportCanvas是一款非常实用的可将canvas图像导出为多种格式图片的jQuery插件。该canvas图像导出插件使用浏览器的下载功能将canvas中的图像下载到本地,你可以指定多种类型的图片格式:PNG,JPEG,GIF,BMP,WEBP。

使用方法

在页面中引入jQuery和export-canvas.js文件。

导出图片

按照下面的格式编写js代码,即可将canvas中的图像通过浏览器下载到本地。

// The ID of canvas element you want to export

var exampleCanvasID = "myCanvas";

var exportCanvas = new ExportCanvas();

// Load the config & language javascript files

exportCanvas.loadConfigFile("core/config/config.js");

exportCanvas.loadLanguageFile("core/language/de.js");

// Set the MIMEType

exportCanvas.setMimeType("image/jpeg");

// Set the quality level when exporting (0.1 - 1.0)

exportCanvas.setExportQuality(1.0);

// The export method

exportCanvas.export(exampleCanvasID, function() {

// callback function

}, function(getLastReport) {

// callback function fired after the download has failed

});

// Export canvas without callbacks

exportCanvas.export(exampleCanvasID);

// Export canvas on document ready

window.onload = function() {

exportCanvas.export(exampleCanvasID);

插件中提供了两种语言:德语和英语。可以通过.loadLanguageFile()方法来切换。setMimeType()方法用于设置导出图片的类型。setExportQuality()是导出图片的质量,取值在0.1-1.0之间。最后可以使用export方法来导出图片。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值