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

Improved Image Fit with Fastly #1976

Merged
merged 5 commits into from
Nov 15, 2019
Merged

Conversation

supernova-at
Copy link
Contributor

Description

tl;dr

This PR adds a fit=cover image optimization parameter to the srcset urls of resource images. This will be ignored by express-sharp, which already produces the intended behavior, but will instruct Fastly to resize the image to entirely cover the given width / height dimensions.

See https://docs.fastly.com/api/imageopto/fit for more details.

Overview

The CategoryTile images on the homepage of our staging site (upward-php + fastly) did not look good:

Screen Shot 2019-11-14 at 11 27 29 AM

Compare that to the latest develop (upward-js):

Screen Shot 2019-11-14 at 11 28 41 AM

Investigation

We were sending the same image resize parameters (width=80, height=100) in both places but getting much different responses back:

upward-php + fastly:
80x100
Screen Shot 2019-11-14 at 8 29 42 AM

upward-js:
178x100
Screen Shot 2019-11-14 at 8 29 37 AM

Resolution

This is because our onboard image optimization middleware (powered by express-sharp) was handling things differently than Fastly when both width and height resize parameters were present. Since we wanted Fastly to emulate the express-sharp way, this PR updates the urls in resource image srcsets to include fit=cover, which will resize the image to entirely cover the given width & height dimensions.

Support for this property was already present in our makeUrl utility, with the following comment:

Fit does not do anything within express-sharp, this is used within Fastly to achieve the same output of desired cropping: https://docs.fastly.com/api/imageopto/fit. Passing this to express-sharp doesn't have any side effects.

See also https://docs.fastly.com/api/imageopto/fit.

Related Issue

Closes PWA-159.

Acceptance

Verification Stakeholders

@tjwiebell @zetlen

Specification

Verification Steps

  1. Go to the homepage of a fastly-enabled site
  2. See that the images are correct (not squished)

Screenshots / Screen Captures (if appropriate)

Checklist

  • I have updated the documentation accordingly, if necessary.
  • I have added tests to cover my changes, if necessary.

@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Nov 14, 2019

Messages
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next nightly build run (assuming they are fixed).
📖

Associated JIRA tickets: PWA-159.

Generated by 🚫 dangerJS against 653b2de

@@ -15,6 +15,7 @@
display: block;
height: 5rem;
object-fit: cover;
object-position: center;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't strictly necessary I suppose, the initial value of 50% 50% will have the same result.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unless you think it's better for readability (ie. the common developer doesn't know centering is the default), let's remove it. Not going to block my approval though.

@@ -21,7 +21,8 @@ const generateURL = (imageURL, mediaBase) => (width, height) => {
const url = resourceUrl(imageURL, {
type: mediaBase,
width,
height
height,
fit: 'cover'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the change that actually fixes the issue.

@supernova-at supernova-at added the version: Patch This changeset includes backwards compatible bug fixes. label Nov 14, 2019
Copy link
Contributor

@tjwiebell tjwiebell left a comment

Choose a reason for hiding this comment

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

Works perfectly, nice work. If you'd like to remove the redundant CSS rule, sneak that in before Dev finishes QA ⏲

@@ -15,6 +15,7 @@
display: block;
height: 5rem;
object-fit: cover;
object-position: center;
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless you think it's better for readability (ie. the common developer doesn't know centering is the default), let's remove it. Not going to block my approval though.

@dpatil-magento dpatil-magento merged commit 15eb774 into develop Nov 15, 2019
@dpatil-magento dpatil-magento deleted the supernova/159_image_ratio branch November 15, 2019 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:venia-ui version: Patch This changeset includes backwards compatible bug fixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants