close #263 option to make >thumbSize gif images have animated thumbnails, smaller gifs always static

merge-requests/208/head
Thomas Lynch 4 years ago
parent d6022c9bf8
commit 6c0d4271ec
  1. 3
      configs/main.js.example
  2. 5
      helpers/files/imagethumbnail.js
  3. 16
      models/forms/makepost.js

@ -121,6 +121,9 @@ module.exports = {
in which case png is used. */
thumbExtension: '.jpg',
//gif images > thumbnail size will have animated thumbnails
animatedGifThumbnails: false,
//max thumb dimensions (square) in px. images smaller than this are not thumbnailed
thumbSize: 250,

@ -2,10 +2,11 @@ const gm = require('gm')
, { thumbSize } = require(__dirname+'/../../configs/main.js')
, uploadDirectory = require(__dirname+'/uploadDirectory.js');
module.exports = (file) => {
module.exports = (file, firstFrameOnly=true) => {
return new Promise((resolve, reject) => {
gm(`${uploadDirectory}/file/${file.filename}[0]`) //0 for first gif frame
//[0] for first frame (gifs, etc)
gm(`${uploadDirectory}/file/${file.filename}${firstFrameOnly ? '[0]' : ''}`)
.resize(Math.min(thumbSize, file.geometry.width), Math.min(thumbSize, file.geometry.height))
.write(`${uploadDirectory}/file/thumb-${file.hash}${file.thumbextension}`, function (err) {
if (err) {

@ -25,7 +25,7 @@ const path = require('path')
, deletePosts = require(__dirname+'/deletepost.js')
, spamCheck = require(__dirname+'/../../helpers/checks/spamcheck.js')
, { checkRealMimeTypes, thumbSize, thumbExtension, videoThumbPercentage,
postPasswordSecret, strictFiltering } = require(__dirname+'/../../configs/main.js')
postPasswordSecret, strictFiltering, animatedGifThumbnails } = require(__dirname+'/../../configs/main.js')
, buildQueue = require(__dirname+'/../../queue.js')
, dynamicResponse = require(__dirname+'/../../helpers/dynamic.js')
, { buildThread } = require(__dirname+'/../../helpers/tasks.js');
@ -255,15 +255,23 @@ module.exports = async (req, res, next) => {
const existsThumb = await pathExists(`${uploadDirectory}/file/thumb-${processedFile.hash}${processedFile.thumbextension}`);
processedFile.geometry = imageData.size ;
processedFile.geometryString = imageData.Geometry;
const lteThumbSize = (processedFile.geometry.height <= thumbSize
&& processedFile.geometry.width <= thumbSize);
processedFile.hasThumb = !(mimeTypes.allowed(file.mimetype, {image: true})
&& subtype !== 'png'
&& processedFile.geometry.height <= thumbSize
&& processedFile.geometry.width <= thumbSize);
&& lteThumbSize);
if (!existsFull) {
await moveUpload(file, processedFile.filename, 'file');
}
if (!existsThumb && processedFile.hasThumb) {
await imageThumbnail(processedFile);
let firstFrameOnly = true;
if (!lteThumbSize
&& file.mimetype === 'image/gif'
&& animatedGifThumbnails === true) {
firstFrameOnly = false;
processedFile.thumbextension = '.gif';
}
await imageThumbnail(processedFile, firstFrameOnly);
}
processedFile = fixGifs(processedFile);
break;

Loading…
Cancel
Save