diff --git a/install/data/defaults.json b/install/data/defaults.json index e41f0dc966..beacb2f00d 100644 --- a/install/data/defaults.json +++ b/install/data/defaults.json @@ -33,10 +33,11 @@ "allowUserHomePage": 1, "allowMultipleBadges": 0, "maximumFileSize": 2048, - "maximumImageWidth": 760, + "resizeImageWidthThreshold": 2000, + "resizeImageWidth": 760, "rejectImageWidth": 5000, "rejectImageHeight": 5000, - "resizeImageQuality": 60, + "resizeImageQuality": 80, "topicThumbSize": 120, "minimumTitleLength": 3, "maximumTitleLength": 255, diff --git a/public/language/en-GB/admin/settings/uploads.json b/public/language/en-GB/admin/settings/uploads.json index 83a0c73428..10e53d7e32 100644 --- a/public/language/en-GB/admin/settings/uploads.json +++ b/public/language/en-GB/admin/settings/uploads.json @@ -4,8 +4,10 @@ "private": "Make uploaded files private", "private-extensions": "File extensions to make private", "private-uploads-extensions-help": "Enter comma-separated list of file extensions to make private here (e.g. pdf,xls,doc). An empty list means all files are private.", - "max-image-width": "Resize images down to specified width (in pixels)", - "max-image-width-help": "(in pixels, default: 760 pixels, set to 0 to disable)", + "resize-image-width-threshold": "Resize images if they are wider than specified width", + "resize-image-width-threshold-help": "(in pixels, default: 1520 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-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)", diff --git a/src/controllers/uploads.js b/src/controllers/uploads.js index f4313fed0a..5ea85d7b6b 100644 --- a/src/controllers/uploads.js +++ b/src/controllers/uploads.js @@ -71,7 +71,7 @@ function uploadAsImage(req, uploadedFile, callback) { uploadsController.uploadFile(req.uid, uploadedFile, next); }, function (fileObj, next) { - if (meta.config.maximumImageWidth === 0) { + if (meta.config.resizeImageWidth === 0 || meta.config.resizeImageWidthThreshold === 0) { return next(null, fileObj); } @@ -112,14 +112,14 @@ function resizeImage(fileObj, callback) { image.size(fileObj.path, next); }, function (imageData, next) { - if (imageData.width < meta.config.maximumImageWidth) { + if (imageData.width < meta.config.resizeImageWidthThreshold || meta.config.resizeImageWidth > meta.config.resizeImageWidthThreshold) { return callback(null, fileObj); } image.resizeImage({ path: fileObj.path, target: file.appendToFileName(fileObj.path, '-resized'), - width: meta.config.maximumImageWidth, + width: meta.config.resizeImageWidth, quality: meta.config.resizeImageQuality, }, next); }, diff --git a/src/upgrades/1.11.0/resize_image_width.js b/src/upgrades/1.11.0/resize_image_width.js new file mode 100644 index 0000000000..60d98f9991 --- /dev/null +++ b/src/upgrades/1.11.0/resize_image_width.js @@ -0,0 +1,24 @@ +'use strict'; + +var db = require('../../database'); + +var async = require('async'); + +module.exports = { + name: 'Rename maximumImageWidth to resizeImageWidth', + timestamp: Date.UTC(2018, 9, 24), + method: function (callback) { + const meta = require('../../meta'); + async.waterfall([ + function (next) { + meta.configs.get('maximumImageWidth', next); + }, + function (value, next) { + meta.configs.set('resizeImageWidth', value, next); + }, + function (next) { + db.deleteObjectField('config', 'maximumImageWidth', next); + }, + ], callback); + }, +}; diff --git a/src/views/admin/settings/post.tpl b/src/views/admin/settings/post.tpl index c1bf5a780d..b95e13fc7d 100644 --- a/src/views/admin/settings/post.tpl +++ b/src/views/admin/settings/post.tpl @@ -28,29 +28,29 @@
[[admin/settings/post:length]]
-
-
-
- - -
-
- - -
-
-
-
- - -
-
- - +
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
-
-
@@ -71,7 +71,7 @@ - +
@@ -98,7 +98,7 @@
- +
@@ -113,7 +113,7 @@ [[admin/settings/post:restrictions.post-queue-help]]

- +
diff --git a/src/views/admin/settings/uploads.tpl b/src/views/admin/settings/uploads.tpl index d008b0d9d3..175aef06fc 100644 --- a/src/views/admin/settings/uploads.tpl +++ b/src/views/admin/settings/uploads.tpl @@ -28,12 +28,26 @@

-
- - -

- [[admin/settings/uploads:max-image-width-help]] -

+
+
+
+ + +

+ [[admin/settings/uploads:resize-image-width-threshold-help]] +

+
+
+ +
+
+ + +

+ [[admin/settings/uploads:resize-image-width-help]] +

+
+
@@ -89,6 +103,7 @@
+
diff --git a/test/uploads.js b/test/uploads.js index 9da7056941..092813108a 100644 --- a/test/uploads.js +++ b/test/uploads.js @@ -108,15 +108,17 @@ describe('Upload Controllers', function () { }); it('should resize and upload an image to a post', function (done) { - var oldValue = meta.config.maximumImageWidth; - meta.config.maximumImageWidth = 10; + var oldValue = meta.config.resizeImageWidth; + meta.config.resizeImageWidth = 10; + meta.config.resizeImageWidthThreshold = 10; helpers.uploadFile(nconf.get('url') + '/api/post/upload', path.join(__dirname, '../test/files/test.png'), {}, jar, csrf_token, function (err, res, body) { assert.ifError(err); assert.equal(res.statusCode, 200); assert(Array.isArray(body)); assert(body[0].url); assert(body[0].url.match(/\/assets\/uploads\/files\/\d+-test-resized\.png/)); - meta.config.maximumImageWidth = oldValue; + meta.config.resizeImageWidth = oldValue; + meta.config.resizeImageWidthThreshold = 1520; done(); }); });