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