Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/sharp resizer #24

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

carlosescura
Copy link

I've been updating the old ImageMagick with the newer and faster sharp image processor.
In addition, this new branch checks and resizes (if needed) the size of the uploaded image according to forum's general settings.

Original benchmark results:
screen shot 2017-04-12 at 15 29 32

Copy link
Owner

@LouiseMcMahon LouiseMcMahon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR it looks interesting and something i would like to merge could you just take a look at my comment on 232.

@@ -231,35 +229,27 @@ plugin.uploadImage = function (data, callback) {
}

fs.readFile(image.path, function (err, buffer) {
uploadToS3(image.name, err, buffer, callback);
var maxWidth = parseInt(meta.config.maximumImageWidth);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct. I looks like it will try to resize files? that are not images.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "normal" files and images are processed in different hooks and therefore in different handler methods.

Normal files are processed by plugin.uploadFile

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It kind of is there are cases when both hooks are called or when a file can be passed to the image hook so its best to just let that through. I've not used sharp and don't know what errors it gives but a try catch around the resize and just uploading if it fails would be best I think.

@@ -6,14 +6,13 @@ var AWS = require("aws-sdk"),
fs = require("fs"),
request = require("request"),
path = require("path"),
sharp = module.parent.require("sharp"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be wrong but this looks like it would try and require sharp from nodebb not the s3-uploads package?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right with your thought but let me explain the reason of using the import in that way:

If I use sharp = require("sharp") it works fine in my local dev environment as it should, but when I use the same import statement in Heroku containers, the index.js of the plugin throws an error saying that sharp package could not be found.
I also saw that "sharp" package was being installed inside the "nodebb -> node_modules" folder and not in "nodebb -> node_modules -> s3-uploader -> node_modules" after a clean nodebb install.

With sharp = module.parent.require("sharp") approach, it works in both local devel and Heroku containers.

Why?
Well... it's a weird behaviour that I can't explain better, but it works

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NPM will sometimes install it in the nodebb -> node_modules folder but it should always put a reference to it in the s3-uploader -> node_modules -> bin folder as far as I'm aware. This sounds more like a bug with heroku and npm than the code. I'm also reticent to try and add fixes for specific platforms as the plugin needs to support all platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants