Permalink
Browse files

Return correct file extension for File objects returned by mozGetFile.

  • Loading branch information...
1 parent 7466fb4 commit cdd92c3d06a8b9ab74b169682639e005364ae4b6 @blueimp committed Feb 11, 2012
Showing with 9 additions and 5 deletions.
  1. +7 −3 canvas-to-blob.js
  2. +1 −1 canvas-to-blob.min.js
  3. +1 −1 package.json
View
@@ -1,5 +1,5 @@
/*
- * JavaScript Canvas to Blob 1.0
+ * JavaScript Canvas to Blob 1.0.1
* https://github.com/blueimp/JavaScript-Canvas-to-Blob
*
* Copyright 2012, Sebastian Tschan
@@ -12,23 +12,27 @@
* http://stackoverflow.com/q/4998908
*/
-/*jslint nomen: true */
+/*jslint nomen: true, regexp: true */
/*global window, atob, ArrayBuffer, Uint8Array, define */
(function ($) {
'use strict';
var BlobBuilder = window.MozBlobBuilder ||
window.WebKitBlobBuilder || window.BlobBuilder,
+ blobTypes = /^image\/(jpeg|png)$/,
+
// Converts a canvas element to a Blob or File object:
canvasToBlob = function (canvas, callback, options) {
options = options || {};
if (canvas.toBlob) {
canvas.toBlob(callback, options.type);
return true;
} else if (canvas.mozGetAsFile) {
+ var name = options.name;
callback(canvas.mozGetAsFile(
- options.name || 'blob.png',
+ (blobTypes.test(options.type) && name) ||
+ ((name && name.replace(/\..+$/, '')) || 'blob') + '.png',
options.type
));
return true;
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,6 +1,6 @@
{
"name": "blueimp-canvas-to-blob",
- "version": "1.0.0",
+ "version": "1.0.1",
"title": "JavaScript Canvas to Blob",
"description": "JavaScript Canvas to Blob is a function to convert canvas elements into Blob objects.",
"keywords": [

0 comments on commit cdd92c3

Please sign in to comment.