Create thumbnails from uploading files (image/video)
npm install file-upload-thumbnailCreate thumbnails from uploading files (image/video).
Extracted from Dropzone.
``bash`
$ npm install --save file-upload-thumbnail
Below is a example of usage.
`javascript`
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;
});
#### fileFile
type: File
the file selected from the input or a instance
#### onSuccess(src) (optional)Function
type: undefined
default: src
callback, parameter is base64 String representing the thumbnail image
#### onError (optional)Function
type: undefined
default:
callback
#### maxWidth (optional)Int
type: undefined
default: undefined
maximal width of the thumbnail, if , the ratio of the image will be used to calculate it.
#### maxHeight (optional)Int
type: undefined
default: maxHeight
the same as . If both (maxWidth and maxHeight) are undefined`, images will not be resized.