|
|
|
@ -14,7 +14,7 @@ limitations under the License.
|
|
|
|
|
|
|
|
|
|
const Promise = require('bluebird');
|
|
|
|
|
const sanitize = require('sanitize-html');
|
|
|
|
|
require("blueimp-canvas-to-blob");
|
|
|
|
|
//require("blueimp-canvas-to-blob");
|
|
|
|
|
const COLOR_REGEX = /^#[0-9a-fA-F]{6}$/;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -41,7 +41,7 @@ module.exports = {
|
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
|
const MAX_WIDTH = 800;
|
|
|
|
|
const MAX_HEIGHT = 600;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let targetWidth = inputWidth;
|
|
|
|
|
let targetHeight = inputHeight;
|
|
|
|
|
if (targetHeight > MAX_HEIGHT) {
|
|
|
|
@ -52,7 +52,7 @@ module.exports = {
|
|
|
|
|
targetHeight = Math.floor(targetHeight * (MAX_WIDTH / targetWidth));
|
|
|
|
|
targetWidth = MAX_WIDTH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const canvas = document.createElement("canvas");
|
|
|
|
|
canvas.width = targetWidth;
|
|
|
|
|
canvas.height = targetHeight;
|
|
|
|
@ -74,7 +74,7 @@ module.exports = {
|
|
|
|
|
}, mimeType);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load a file into a newly created image element.
|
|
|
|
|
*
|
|
|
|
@ -87,7 +87,7 @@ module.exports = {
|
|
|
|
|
const img = document.createElement("img");
|
|
|
|
|
const objectUrl = URL.createObjectURL(imageFile);
|
|
|
|
|
img.src = objectUrl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Once ready, create a thumbnail
|
|
|
|
|
img.onload = function() {
|
|
|
|
|
URL.revokeObjectURL(objectUrl);
|
|
|
|
@ -109,14 +109,16 @@ module.exports = {
|
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
|
// Load the file into an html element
|
|
|
|
|
const video = document.createElement("video");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
|
reader.onload = function(e) {
|
|
|
|
|
video.src = e.target.result;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Once ready, returns its size
|
|
|
|
|
// Wait until we have enough data to thumbnail the first frame.
|
|
|
|
|
video.onloadeddata = function() {
|
|
|
|
|
video.width = video.videoWidth
|
|
|
|
|
video.height = video.videoHeight
|
|
|
|
|
resolve(video);
|
|
|
|
|
};
|
|
|
|
|
video.onerror = function(e) {
|
|
|
|
|