• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

blueimp/JavaScript-Canvas-to-Blob: JavaScript Canvas to Blob is a function to co ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

blueimp/JavaScript-Canvas-to-Blob

开源软件地址:

https://github.com/blueimp/JavaScript-Canvas-to-Blob

开源编程语言:

JavaScript 91.0%

开源软件介绍:

JavaScript Canvas to Blob

Contents

Description

Canvas to Blob is a polyfill for Browsers that don't support the standard JavaScript HTMLCanvasElement.toBlob method.

It can be used to create Blob objects from an HTML canvas element.

Setup

Install via NPM:

npm install blueimp-canvas-to-blob

This will install the JavaScript files inside ./node_modules/blueimp-canvas-to-blob/js/ relative to your current directory, from where you can copy them into a folder that is served by your web server.

Next include the minified JavaScript Canvas to Blob script in your HTML markup:

<script src="js/canvas-to-blob.min.js"></script>

Or alternatively, include the non-minified version:

<script src="js/canvas-to-blob.js"></script>

Usage

You can use the canvas.toBlob() method in the same way as the native implementation:

var canvas = document.createElement('canvas')
// Edit the canvas ...
if (canvas.toBlob) {
  canvas.toBlob(function (blob) {
    // Do something with the blob object,
    // e.g. create multipart form data for file uploads:
    var formData = new FormData()
    formData.append('file', blob, 'image.jpg')
    // ...
  }, 'image/jpeg')
}

Requirements

The JavaScript Canvas to Blob function has zero dependencies.

However, it is a very suitable complement to the JavaScript Load Image function.

Browsers

The following browsers have native support for HTMLCanvasElement.toBlob:

  • Chrome 50+
  • Firefox 19+
  • Safari 11+
  • Mobile Chrome 50+ (Android)
  • Mobile Firefox 4+ (Android)
  • Mobile Safari 11+ (iOS)
  • Edge 79+

Browsers which implement the following APIs support canvas.toBlob() via polyfill:

This includes the following browsers:

  • Chrome 20+
  • Firefox 13+
  • Safari 8+
  • Mobile Chrome 25+ (Android)
  • Mobile Firefox 14+ (Android)
  • Mobile Safari 8+ (iOS)
  • Edge 74+
  • Edge Legacy 12+
  • Internet Explorer 10+

API

In addition to the canvas.toBlob() polyfill, the JavaScript Canvas to Blob script exposes its helper function dataURLtoBlob(url):

// Uncomment the following line when using a module loader like webpack:
// var dataURLtoBlob = require('blueimp-canvas-to-blob')

// black+white 3x2 GIF, base64 data:
var b64 = 'R0lGODdhAwACAPEAAAAAAP///yZFySZFySH5BAEAAAIALAAAAAADAAIAAAIDRAJZADs='
var url = 'data:image/gif;base64,' + b64
var blob = dataURLtoBlob(url)

Test

Unit tests

License

The JavaScript Canvas to Blob script is released under the MIT license.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
whatwg/javascript: Obsolete发布时间:2022-06-24
下一篇:
jscomplete/learn-fullstack-javascript: For help, ask in #questions at jscomplete ...发布时间:2022-06-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap