Skip to content
This repository has been archived by the owner on May 8, 2021. It is now read-only.

Commit

Permalink
Updated #57 支持传入base64,感谢@lsycxyj
Browse files Browse the repository at this point in the history
  • Loading branch information
think2011 committed Nov 24, 2015
1 parent cf72b1e commit 74649fb
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lrz",
"version": "4.7.35",
"version": "4.8.35",
"homepage": "https://github.com/think2011/localResizeIMG",
"authors": [
"think2011 <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion dist/lrz.all.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lrz.all.bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lrz.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lrz.bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lrz",
"version": "4.7.35",
"version": "4.8.35",
"description": "前端本地客户端压缩图片,兼容IOS,Android,PC、自动按需加载文件",
"scripts": {
"test": "node ./node_modules/karma/bin/karma start"
Expand Down
17 changes: 12 additions & 5 deletions src/lrz.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,20 @@ Lrz.prototype.init = function () {
var that = this,
file = that.file,
fileIsString = typeof file === 'string',
fileIsBase64 = /^data:/.test(file),
img = new Image(),
canvas = document.createElement('canvas'),
blob = fileIsString ? file : URL.createObjectURL(file);

that.img = img;
that.blob = blob;
that.canvas = canvas;
that.fileName = fileIsString ? (file.split('/').pop()) : file.name;
that.img = img;
that.blob = blob;
that.canvas = canvas;

if (fileIsString) {
that.fileName = fileIsBase64 ? 'base64.jpg' : (file.split('/').pop());
} else {
that.fileName = file.name;
}

if (!document.createElement('canvas').getContext) {
throw new Error('浏览器不支持canvas');
Expand Down Expand Up @@ -111,7 +117,8 @@ Lrz.prototype.init = function () {
});
};

img.crossOrigin = "*";
// 如果传入的是base64在移动端会报错
!fileIsBase64 && (img.crossOrigin = "*");

img.src = blob;
});
Expand Down
2 changes: 1 addition & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ <h3>旋转方向测试</h3>
</footer>


<script src="../dist/lrz.bundle.js?v=69f2c4b"></script>
<script src="../dist/lrz.bundle.js?v=a1a6749"></script>
<script src="./index.js?v=27ce5f7"></script>
</body>
</html>
11 changes: 10 additions & 1 deletion test/lrz.spec.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/server.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ <h3>旋转方向测试</h3>
</footer>


<script src="../dist/lrz.bundle.js?v=69f2c4b"></script>
<script src="../dist/lrz.bundle.js?v=a1a6749"></script>
<script src="./server.js?v=c8aaa97"></script>
</body>
</html>

0 comments on commit 74649fb

Please sign in to comment.