mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: changes to thumb resizing logic
- Resized thumb no longer skews aspect ratio - Thumbs resized down to maximum thumb size by WIDTH only - image.checkDimensions() now returns dimensions
This commit is contained in:
@@ -120,12 +120,14 @@ uploadsController.uploadThumb = async function (req, res) {
|
|||||||
throw new Error('[[error:invalid-file]]');
|
throw new Error('[[error:invalid-file]]');
|
||||||
}
|
}
|
||||||
await image.isFileTypeAllowed(uploadedFile.path);
|
await image.isFileTypeAllowed(uploadedFile.path);
|
||||||
await image.checkDimensions(uploadedFile.path);
|
const dimensions = await image.checkDimensions(uploadedFile.path);
|
||||||
await image.resizeImage({
|
|
||||||
path: uploadedFile.path,
|
if (dimensions.width > parseInt(meta.config.topicThumbSize, 10)) {
|
||||||
width: meta.config.topicThumbSize,
|
await image.resizeImage({
|
||||||
height: meta.config.topicThumbSize,
|
path: uploadedFile.path,
|
||||||
});
|
width: meta.config.topicThumbSize,
|
||||||
|
});
|
||||||
|
}
|
||||||
if (plugins.hooks.hasListeners('filter:uploadImage')) {
|
if (plugins.hooks.hasListeners('filter:uploadImage')) {
|
||||||
return await plugins.hooks.fire('filter:uploadImage', {
|
return await plugins.hooks.fire('filter:uploadImage', {
|
||||||
image: uploadedFile,
|
image: uploadedFile,
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ image.checkDimensions = async function (path) {
|
|||||||
if (result.width > meta.config.rejectImageWidth || result.height > meta.config.rejectImageHeight) {
|
if (result.width > meta.config.rejectImageWidth || result.height > meta.config.rejectImageHeight) {
|
||||||
throw new Error('[[error:invalid-image-dimensions]]');
|
throw new Error('[[error:invalid-image-dimensions]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
image.convertImageToBase64 = async function (path) {
|
image.convertImageToBase64 = async function (path) {
|
||||||
|
|||||||
Reference in New Issue
Block a user