Skip to content

Commit cdd92c3

Browse files
committed
Return correct file extension for File objects returned by mozGetFile.
1 parent 7466fb4 commit cdd92c3

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

canvas-to-blob.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* JavaScript Canvas to Blob 1.0
2+
* JavaScript Canvas to Blob 1.0.1
33
* https://github.com/blueimp/JavaScript-Canvas-to-Blob
44
*
55
* Copyright 2012, Sebastian Tschan
@@ -12,23 +12,27 @@
1212
* http://stackoverflow.com/q/4998908
1313
*/
1414

15-
/*jslint nomen: true */
15+
/*jslint nomen: true, regexp: true */
1616
/*global window, atob, ArrayBuffer, Uint8Array, define */
1717

1818
(function ($) {
1919
'use strict';
2020

2121
var BlobBuilder = window.MozBlobBuilder ||
2222
window.WebKitBlobBuilder || window.BlobBuilder,
23+
blobTypes = /^image\/(jpeg|png)$/,
24+
2325
// Converts a canvas element to a Blob or File object:
2426
canvasToBlob = function (canvas, callback, options) {
2527
options = options || {};
2628
if (canvas.toBlob) {
2729
canvas.toBlob(callback, options.type);
2830
return true;
2931
} else if (canvas.mozGetAsFile) {
32+
var name = options.name;
3033
callback(canvas.mozGetAsFile(
31-
options.name || 'blob.png',
34+
(blobTypes.test(options.type) && name) ||
35+
((name && name.replace(/\..+$/, '')) || 'blob') + '.png',
3236
options.type
3337
));
3438
return true;

canvas-to-blob.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blueimp-canvas-to-blob",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"title": "JavaScript Canvas to Blob",
55
"description": "JavaScript Canvas to Blob is a function to convert canvas elements into Blob objects.",
66
"keywords": [

0 commit comments

Comments
 (0)