-
Notifications
You must be signed in to change notification settings - Fork 78
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
Fix for files that are rotated after resizing #1
Conversation
Hi Adam Thank you for contributing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of your contribution, we are going to avoid deprecated methods. Which means s3-resizer
is still supported.
I also see that this repository helps people and it really makes me happy.
Thank you again!
index.js
Outdated
@@ -45,7 +45,7 @@ exports.handler = function(event, _context, callback) { | |||
return new Promise(() => {}) // the next then-blocks will never be executed | |||
} | |||
|
|||
return img.withoutEnlargement().toBuffer(); | |||
return img.withoutEnlargement().rotate().toBuffer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v0.21 Changelog says that .withoutEnlargement
, .max
, and .min
are deprecated.
It seems we need to change .resize
method above on :L30 to
.resize(..., ..., {withoutEnlargement: true, fit})
.
Where fit
is null | 'inside' | 'outside'
. I.e.
var fit;
switch (func) {
case 'max': fit = 'inside'; break;
case 'min': fit = 'outside'; break;
case null: fit = null; break;
default: // ...
}
And could you please explain why should we have calling .rotate()
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing - will do those changes. rotate function should rotate the image according to EXIF info: https://sharp.pixelplumbing.com/en/stable/api-operation/#rotate. the image I've attached is from an Android device - when you view the original image it's in portrait. but when I've resized it with your library it's resized to a landscape image. to fix this I've added the portrait call - that will rotate the image back to original position using EXIF info.
README.md
Outdated
@@ -147,7 +147,7 @@ or | |||
* * Go to lambda, click on **Test**, and paste this json: | |||
```json | |||
{ | |||
"queryStringParameters": {"path": __YOUR_IMAGE_PATH_WITH_SIZE_PREFIX__} | |||
"queryStringParameters": {"path": "__YOUR_IMAGE_PATH_WITH_SIZE_PREFIX__"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally have written the value that way.
Firstly, it's red and captures a look immediately.
Secondly, even if a user copies and pastes it as it is, it is invalid json, so it is going to throw an error.
However, in case you are able to give a good explanation why the changed code is better, we can continue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I see - it caused me an invalid JSON as well that's why I wanted to fix it. But your reasoning makes sense! I'll revert that change :)
This reverts commit 39fce84.
updated my PR @sagidM |
It seems you've forgotten to use Since in one-line object there's no spaces, it contrasts using spaces in one place. By the way, I don't remember why I chose that name; would not it be better to rename |
ohhh right - I've added that missing handler for func. Yeah that was a good shout to rename |
Okay, we have done here. |
Did that by mistake... |
Awesome - thanks for all the suggestions on the PR :) |
Example image to reproduce the issue:
http://smartuploader.s3-website-us-east-1.amazonaws.com/uploads/sizes/1548235941338/0ca4075d-4039-4fbe-8341-32f0ee75a2a2.jpeg