-
Notifications
You must be signed in to change notification settings - Fork 683
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]: Add height to makeUrl
and enforce crop in middleware if provided
#1361
Conversation
This pull request is automatically deployed with Now. Latest deployment for this branch: https://venia-git-fix-image-resize-height.magento-research1.now.sh |
|
The URLs made by The reason we follow Fastly's image opto API is that we want our customers to be on Enterprise Cloud and to have Fastly IO enabled; that should be the "happy path" and the simplest thing. In that simplest case, Fastly takes over all the image manipulation (and it's super fast at it). Since Fastly is an external service and our express-sharp implementation is an internal one, we can freely mess with the So you just gotta change so Test it by connecting your local instance to one of our Fastly-enabled Enterprise Cloud shops. Then set the env var |
Looks like Fastly is actually a good citizen when it comes to resizing. When you give a height and width that don't match the aspect ratio they must resize the image automatically whereas express-sharp retains the aspect ratio and matches the latter param (height). So what I need to do is figure out if there is a way to get express-sharp to resize in the same way that fastly does (looks like crop is the answer right now). |
makeUrl
and enforce crop in middleware if provided
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.
Should be no need to throw error, then this looks good to me.
@tjwiebell addressed feedback. Please move to Ready for QA if it looks good! |
@sirugh Other than below observations rest all looks good.
|
Expected, we are now requesting
So that's not actually an intentional border. It is the overlap of the placeholder that is sized slightly too large and ends up showing a bit below the full image. The fact that it is no longer visible is intentional, and is in fact one of the primary reasons I wrote this PR :) |
Description
The product images from sample data are 25:31 ratio.
The placeholder image we use is 4:5.
This is a difference of only a few pixels but it leads to a poor UX where we sometimes have a placeholder image that is too large (ie. on the category page) or we have a UI that "shifts" down/up when we render a placeholder and then replace it with the product image (ie. on the pdp).
I made a change here to the
makeUrl
to accept aheight
param. I also added some logic to our middleware to now enforcecrop
if both height and width are provided.To understand these changes consider the following. Say we have an image with ratio 25:31 (as is our sample data) and we want to size it. The following now can happen:
a) Using
width=640
, sharp and fastly will scale to640x796
because they retained the aspect ratio.b) Using
width=640&height=800
, fastly will scale to640x800
but sharp will scale to645x800
because of thefit: outside
prop used. Now, with these changes sharp will scale and then crop tocover
the provided height and width.If a user wants to retain the aspect ratio of the image using either fastly or our express-sharp, they can still just pass
width
.Read more here:
sharp resize
fastly
Related Issue
Closes #1359 .
Verification Steps
IMAGE_OPTIMIZING_ORIGIN="backend"
in your.env
and re-run your server.How have YOU tested this?
I made a change to the category page
GalleryItem
which is only one implementation ofmakeUrl
. Ideally we would just us these changes elsewhere when we identify a problem.Screenshots / Screen Captures (if appropriate):
In the BEFORE screenshot notice the grey rectangle below the product images.
BEFORE
AFTER
Proposed Labels for Change Type/Package
Checklist: