support thumbnails for .webm and .mp4 files
This commit is contained in:
parent
8cddd06d7a
commit
facf4a29fc
|
@ -45,6 +45,7 @@ module.exports = {
|
|||
|
||||
// NOTE: Thumbnails are only for the admin panel and they require you
|
||||
// to install a separate binary called graphicsmagick (http://www.graphicsmagick.org)
|
||||
// for images and FFmpeg (https://ffmpeg.org/) for video files
|
||||
generateThumbnails: false
|
||||
},
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ const db = require('knex')(config.database)
|
|||
const crypto = require('crypto')
|
||||
const fs = require('fs')
|
||||
const gm = require('gm')
|
||||
const ffmpeg = require('fluent-ffmpeg')
|
||||
|
||||
let uploadsController = {}
|
||||
|
||||
|
@ -246,30 +247,45 @@ uploadsController.list = function(req, res){
|
|||
|
||||
if(config.uploads.generateThumbnails === true){
|
||||
|
||||
let extensions = ['.jpg', '.jpeg', '.bmp', '.gif', '.png']
|
||||
let extensions = ['.jpg', '.jpeg', '.bmp', '.gif', '.png', '.webm', '.mp4']
|
||||
for(let ext of extensions){
|
||||
if(path.extname(file.name) === ext){
|
||||
|
||||
file.thumb = basedomain + '/thumbs/' + file.name.slice(0, -4) + '.png'
|
||||
file.thumb = basedomain + '/thumbs/' + file.name.slice(0, -ext.length) + '.png'
|
||||
|
||||
let thumbname = path.join(__dirname, '..', 'uploads', 'thumbs') + '/' + file.name.slice(0, -4) + '.png'
|
||||
let thumbname = path.join(__dirname, '..', config.uploads.folder, 'thumbs') + '/' + file.name.slice(0, -ext.length) + '.png'
|
||||
fs.access(thumbname, function(err) {
|
||||
if (err && err.code === 'ENOENT') {
|
||||
// File doesnt exist
|
||||
|
||||
let size = {
|
||||
width: 200,
|
||||
height: 200
|
||||
if (ext === '.webm' || ext === '.mp4') {
|
||||
ffmpeg('./' + config.uploads.folder + '/' + file.name)
|
||||
.thumbnail({
|
||||
timestamps: [0],
|
||||
filename: '%b.png',
|
||||
folder: './' + config.uploads.folder + '/thumbs',
|
||||
size: '200x?',
|
||||
autopad: true
|
||||
})
|
||||
.on('error', function(error) {
|
||||
console.log('Error - ', error.message)
|
||||
})
|
||||
}
|
||||
else {
|
||||
let size = {
|
||||
width: 200,
|
||||
height: 200
|
||||
}
|
||||
|
||||
gm('./' + config.uploads.folder + '/' + file.name)
|
||||
.resize(size.width, size.height + '>')
|
||||
.gravity('Center')
|
||||
.extent(size.width, size.height)
|
||||
.background('transparent')
|
||||
.write(thumbname, function (error) {
|
||||
if (error) console.log('Error - ', error)
|
||||
})
|
||||
gm('./' + config.uploads.folder + '/' + file.name)
|
||||
.resize(size.width, size.height + '>')
|
||||
.gravity('Center')
|
||||
.extent(size.width, size.height)
|
||||
.background('transparent')
|
||||
.write(thumbname, function (error) {
|
||||
if (error) console.log('Error - ', error)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
"body-parser": "^1.16.0",
|
||||
"express": "^4.14.0",
|
||||
"express-rate-limit": "^2.6.0",
|
||||
"fluent-ffmpeg": "^2.1.0",
|
||||
"gm": "^1.23.0",
|
||||
"knex": "^0.12.6",
|
||||
"multer": "^1.2.1",
|
||||
|
|
Loading…
Reference in New Issue