ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
MIT License
|
||||
|
||||
Copyright © 2012 Sebastian Tschan, https://blueimp.net
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,135 @@
|
||||
# JavaScript Canvas to Blob
|
||||
|
||||
## Contents
|
||||
|
||||
- [Description](#description)
|
||||
- [Setup](#setup)
|
||||
- [Usage](#usage)
|
||||
- [Requirements](#requirements)
|
||||
- [Browsers](#browsers)
|
||||
- [API](#api)
|
||||
- [Test](#test)
|
||||
- [License](#license)
|
||||
|
||||
## Description
|
||||
|
||||
Canvas to Blob is a
|
||||
[polyfill](https://developer.mozilla.org/en-US/docs/Glossary/Polyfill) for
|
||||
Browsers that don't support the standard JavaScript
|
||||
[HTMLCanvasElement.toBlob](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob)
|
||||
method.
|
||||
|
||||
It can be used to create
|
||||
[Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) objects from an
|
||||
HTML [canvas](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas)
|
||||
element.
|
||||
|
||||
## Setup
|
||||
|
||||
Install via [NPM](https://www.npmjs.com/package/blueimp-canvas-to-blob):
|
||||
|
||||
```sh
|
||||
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:
|
||||
|
||||
```html
|
||||
<script src="js/canvas-to-blob.min.js"></script>
|
||||
```
|
||||
|
||||
Or alternatively, include the non-minified version:
|
||||
|
||||
```html
|
||||
<script src="js/canvas-to-blob.js"></script>
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
You can use the `canvas.toBlob()` method in the same way as the native
|
||||
implementation:
|
||||
|
||||
```js
|
||||
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](https://github.com/blueimp/JavaScript-Load-Image)
|
||||
function.
|
||||
|
||||
## Browsers
|
||||
|
||||
The following browsers have native support for
|
||||
[HTMLCanvasElement.toBlob](https://developer.mozilla.org/en-US/docs/Web/API/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:
|
||||
|
||||
- [HTMLCanvasElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement)
|
||||
- [HTMLCanvasElement.toDataURL](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL)
|
||||
- [Blob() constructor](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob)
|
||||
- [atob](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/atob)
|
||||
- [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
|
||||
- [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)
|
||||
|
||||
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)`:
|
||||
|
||||
```js
|
||||
// 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](https://blueimp.github.io/JavaScript-Canvas-to-Blob/test/)
|
||||
|
||||
## License
|
||||
|
||||
The JavaScript Canvas to Blob script is released under the
|
||||
[MIT license](https://opensource.org/licenses/MIT).
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* JavaScript Canvas to Blob
|
||||
* https://github.com/blueimp/JavaScript-Canvas-to-Blob
|
||||
*
|
||||
* Copyright 2012, Sebastian Tschan
|
||||
* https://blueimp.net
|
||||
*
|
||||
* Licensed under the MIT license:
|
||||
* https://opensource.org/licenses/MIT
|
||||
*
|
||||
* Based on stackoverflow user Stoive's code snippet:
|
||||
* http://stackoverflow.com/q/4998908
|
||||
*/
|
||||
|
||||
/* global define, Uint8Array, ArrayBuffer, module */
|
||||
|
||||
;(function (window) {
|
||||
'use strict'
|
||||
|
||||
var CanvasPrototype =
|
||||
window.HTMLCanvasElement && window.HTMLCanvasElement.prototype
|
||||
var hasBlobConstructor =
|
||||
window.Blob &&
|
||||
(function () {
|
||||
try {
|
||||
return Boolean(new Blob())
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
})()
|
||||
var hasArrayBufferViewSupport =
|
||||
hasBlobConstructor &&
|
||||
window.Uint8Array &&
|
||||
(function () {
|
||||
try {
|
||||
return new Blob([new Uint8Array(100)]).size === 100
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
})()
|
||||
var BlobBuilder =
|
||||
window.BlobBuilder ||
|
||||
window.WebKitBlobBuilder ||
|
||||
window.MozBlobBuilder ||
|
||||
window.MSBlobBuilder
|
||||
var dataURIPattern = /^data:((.*?)(;charset=.*?)?)(;base64)?,/
|
||||
var dataURLtoBlob =
|
||||
(hasBlobConstructor || BlobBuilder) &&
|
||||
window.atob &&
|
||||
window.ArrayBuffer &&
|
||||
window.Uint8Array &&
|
||||
function (dataURI) {
|
||||
var matches,
|
||||
mediaType,
|
||||
isBase64,
|
||||
dataString,
|
||||
byteString,
|
||||
arrayBuffer,
|
||||
intArray,
|
||||
i,
|
||||
bb
|
||||
// Parse the dataURI components as per RFC 2397
|
||||
matches = dataURI.match(dataURIPattern)
|
||||
if (!matches) {
|
||||
throw new Error('invalid data URI')
|
||||
}
|
||||
// Default to text/plain;charset=US-ASCII
|
||||
mediaType = matches[2]
|
||||
? matches[1]
|
||||
: 'text/plain' + (matches[3] || ';charset=US-ASCII')
|
||||
isBase64 = !!matches[4]
|
||||
dataString = dataURI.slice(matches[0].length)
|
||||
if (isBase64) {
|
||||
// Convert base64 to raw binary data held in a string:
|
||||
byteString = atob(dataString)
|
||||
} else {
|
||||
// Convert base64/URLEncoded data component to raw binary:
|
||||
byteString = decodeURIComponent(dataString)
|
||||
}
|
||||
// Write the bytes of the string to an ArrayBuffer:
|
||||
arrayBuffer = new ArrayBuffer(byteString.length)
|
||||
intArray = new Uint8Array(arrayBuffer)
|
||||
for (i = 0; i < byteString.length; i += 1) {
|
||||
intArray[i] = byteString.charCodeAt(i)
|
||||
}
|
||||
// Write the ArrayBuffer (or ArrayBufferView) to a blob:
|
||||
if (hasBlobConstructor) {
|
||||
return new Blob([hasArrayBufferViewSupport ? intArray : arrayBuffer], {
|
||||
type: mediaType
|
||||
})
|
||||
}
|
||||
bb = new BlobBuilder()
|
||||
bb.append(arrayBuffer)
|
||||
return bb.getBlob(mediaType)
|
||||
}
|
||||
if (window.HTMLCanvasElement && !CanvasPrototype.toBlob) {
|
||||
if (CanvasPrototype.mozGetAsFile) {
|
||||
CanvasPrototype.toBlob = function (callback, type, quality) {
|
||||
var self = this
|
||||
setTimeout(function () {
|
||||
if (quality && CanvasPrototype.toDataURL && dataURLtoBlob) {
|
||||
callback(dataURLtoBlob(self.toDataURL(type, quality)))
|
||||
} else {
|
||||
callback(self.mozGetAsFile('blob', type))
|
||||
}
|
||||
})
|
||||
}
|
||||
} else if (CanvasPrototype.toDataURL && dataURLtoBlob) {
|
||||
if (CanvasPrototype.msToBlob) {
|
||||
CanvasPrototype.toBlob = function (callback, type, quality) {
|
||||
var self = this
|
||||
setTimeout(function () {
|
||||
if (
|
||||
((type && type !== 'image/png') || quality) &&
|
||||
CanvasPrototype.toDataURL &&
|
||||
dataURLtoBlob
|
||||
) {
|
||||
callback(dataURLtoBlob(self.toDataURL(type, quality)))
|
||||
} else {
|
||||
callback(self.msToBlob(type))
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
CanvasPrototype.toBlob = function (callback, type, quality) {
|
||||
var self = this
|
||||
setTimeout(function () {
|
||||
callback(dataURLtoBlob(self.toDataURL(type, quality)))
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(function () {
|
||||
return dataURLtoBlob
|
||||
})
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
module.exports = dataURLtoBlob
|
||||
} else {
|
||||
window.dataURLtoBlob = dataURLtoBlob
|
||||
}
|
||||
})(window)
|
||||
Reference in New Issue
Block a user