mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-05 07:10:30 +01:00
@@ -52,6 +52,7 @@
|
||||
"orphanExpiryDays": 0,
|
||||
"resizeImageWidthThreshold": 2000,
|
||||
"resizeImageWidth": 760,
|
||||
"resizeImageKeepOriginal": 1,
|
||||
"rejectImageWidth": 5000,
|
||||
"rejectImageHeight": 5000,
|
||||
"resizeImageQuality": 80,
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"resize-image-width-threshold-help": "(in pixels, default: 2000 pixels, set to 0 to disable)",
|
||||
"resize-image-width": "Resize images down to specified width",
|
||||
"resize-image-width-help": "(in pixels, default: 760 pixels, set to 0 to disable)",
|
||||
"resize-image-keep-original": "Keep original image after resize",
|
||||
"resize-image-quality": "Quality to use when resizing images",
|
||||
"resize-image-quality-help": "Use a lower quality setting to reduce the file size of resized images.",
|
||||
"max-file-size": "Maximum File Size (in KiB)",
|
||||
|
||||
@@ -110,12 +110,16 @@ async function resizeImage(fileObj) {
|
||||
|
||||
await image.resizeImage({
|
||||
path: fileObj.path,
|
||||
target: file.appendToFileName(fileObj.path, '-resized'),
|
||||
target: meta.config.resizeImageKeepOriginal ?
|
||||
file.appendToFileName(fileObj.path, '-resized') :
|
||||
fileObj.path,
|
||||
width: meta.config.resizeImageWidth,
|
||||
quality: meta.config.resizeImageQuality,
|
||||
});
|
||||
// Return the resized version to the composer/postData
|
||||
fileObj.url = file.appendToFileName(fileObj.url, '-resized');
|
||||
if (meta.config.resizeImageKeepOriginal) {
|
||||
fileObj.url = file.appendToFileName(fileObj.url, '-resized');
|
||||
}
|
||||
|
||||
return fileObj;
|
||||
}
|
||||
|
||||
@@ -122,7 +122,6 @@ image.stripEXIF = async function (path) {
|
||||
};
|
||||
|
||||
image.checkDimensions = async function (path) {
|
||||
const meta = require('./meta');
|
||||
const result = await image.size(path);
|
||||
|
||||
if (result.width > meta.config.rejectImageWidth || result.height > meta.config.rejectImageHeight) {
|
||||
|
||||
13
src/upgrades/3.12.0/resize-image-keep-original.js
Normal file
13
src/upgrades/3.12.0/resize-image-keep-original.js
Normal file
@@ -0,0 +1,13 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
|
||||
'use strict';
|
||||
|
||||
const db = require('../../database');
|
||||
|
||||
module.exports = {
|
||||
name: 'Add setting for keeping original image after resize',
|
||||
timestamp: Date.UTC(2024, 11, 2),
|
||||
method: async function () {
|
||||
await db.setObjectField('config', 'resizeImageKeepOriginal', 1);
|
||||
},
|
||||
};
|
||||
@@ -46,6 +46,11 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-check form-switch mb-3">
|
||||
<input class="form-check-input" type="checkbox" id="resizeImageKeepOriginal" data-field="resizeImageKeepOriginal">
|
||||
<label for="resizeImageKeepOriginal" class="form-check-label">[[admin/settings/uploads:resize-image-keep-original]]</label>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="resizeImageQuality">[[admin/settings/uploads:resize-image-quality]]</label>
|
||||
<input id="resizeImageQuality" type="text" class="form-control" value="60" data-field="resizeImageQuality" placeholder="60">
|
||||
|
||||
@@ -164,6 +164,24 @@ describe('Upload Controllers', () => {
|
||||
meta.config.resizeImageWidthThreshold = 2000;
|
||||
});
|
||||
|
||||
it('should resize and upload an image to a post and replace original', async () => {
|
||||
const oldValue = meta.config.resizeImageWidth;
|
||||
const keepOldValue = meta.config.resizeImageKeepOriginal;
|
||||
meta.config.resizeImageWidth = 10;
|
||||
meta.config.resizeImageWidthThreshold = 10;
|
||||
meta.config.resizeImageKeepOriginal = 0;
|
||||
const { response, body } = await helpers.uploadFile(`${nconf.get('url')}/api/post/upload`, path.join(__dirname, '../test/files/test.png'), {}, jar, csrf_token);
|
||||
|
||||
assert.equal(response.statusCode, 200);
|
||||
assert(body && body.status && body.response && body.response.images);
|
||||
assert(Array.isArray(body.response.images));
|
||||
assert(body.response.images[0].url);
|
||||
assert(body.response.images[0].url.match(/\/assets\/uploads\/files\/\d+-test.png/));
|
||||
meta.config.resizeImageWidth = oldValue;
|
||||
meta.config.resizeImageWidthThreshold = 2000;
|
||||
meta.config.resizeImageKeepOriginal = keepOldValue;
|
||||
});
|
||||
|
||||
it('should upload a file to a post', async () => {
|
||||
const oldValue = meta.config.allowedFileExtensions;
|
||||
meta.config.allowedFileExtensions = 'png,jpg,bmp,html';
|
||||
|
||||
Reference in New Issue
Block a user