Create thumbnails from uploading files (image/video).
Extracted from Dropzone.
$ npm install --save file-upload-thumbnail
Below is a example of usage.
var FileUploadThumbnail = require('file-upload-thumbnail');
document.getElementById('file').addEventListener('change', function(e) {
e.preventDefault();
if (e.target.files) {
Array.prototype.slice.call(e.target.files).forEach(function(file){
new FileUploadThumbnail({
maxWidth: 500,
maxHeight: 40,
file: file,
onSuccess: function(src){
document.getElementById('preview_image').src = src || '';
}
}).createThumbnail();
});
}
e.target.value = null;
return false;
});
type: File
the file selected from the input or a File
instance
type: Function
default: undefined
callback, parameter src
is base64 String
representing the thumbnail image
type: Function
default: undefined
callback
type: Int
default: undefined
maximal width of the thumbnail, if undefined
, the ratio of the image will be used to calculate it.
type: Int
default: undefined
the same as maxHeight
. If both (maxWidth
and maxHeight
) are undefined
, images will not be resized.