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

Asynchronously detect image aspect ratios and apply proper attributes #15170

Merged
merged 6 commits into from
Oct 26, 2021

Conversation

benhalpern
Copy link
Contributor

@benhalpern benhalpern commented Oct 22, 2021

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

This PR builds on a couple past PRs which have made use of FastImage for detection of size and/or whether an image was animated.

For ideal UX and SEO, it is best when height and width attributes are present on an image. This prevents cumulative layout shift, which is something users hate and so do search engine quality checkers. Plenty about that here:

https://web.dev/optimize-cls/

Before/after videos below, but good examples of current behavior on DEV are the welcome threads where we use a gif: https://dev.to/thepracticaldev/welcome-thread-v147-4mkj

This PR extends an existing pattern we have in place to inspect images for whether they are animated gifs, and applies a check for height/width. It also refactors another place we put this functionality to put it all in one place.

This is performed asynchronously and changes are only made if there are images to change. While FastImage is a great utility for querying for image meta data in the fastest/most minimal way, it is still a query we would rather do asynchronously.

This functionality does current open an image twice in order to check for size and whether it is animated, but I looked through the FastImage docs and code, and it seems like this is the only way they provide via their API. If anyone wants to double check that, please feel welcome.

Note: I left the feature flags in place which were added here: #13906 — I think we could disable them at some point if this has been deemed stable? Seems like the feature flag has just been on with DEV and things seem okay. Will need more info.

Related Tickets & Documents

https://github.com/forem/rfcs/issues/243

#13766

#14789

QA Instructions, Screenshots, Recordings

Before

before_detection.mov

After

after_detection.mov

Added/updated tests?

  • Yes

@benhalpern benhalpern requested a review from a team as a code owner October 22, 2021 23:24
@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Oct 22, 2021
@pr-triage pr-triage bot added PR: partially-approved bot applied label for PR's where a single reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Oct 25, 2021
Co-authored-by: Michael Kohl <citizen428@forem.com>
@pr-triage pr-triage bot added PR: unreviewed bot applied label for PR's with no review and removed PR: partially-approved bot applied label for PR's where a single reviewer approves changes labels Oct 25, 2021
@pr-triage pr-triage bot added PR: partially-approved bot applied label for PR's where a single reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Oct 26, 2021
@benhalpern benhalpern merged commit 2395693 into main Oct 26, 2021
@benhalpern benhalpern deleted the ben/detect-image-ratios-in-articles branch October 26, 2021 20:39
@pr-triage pr-triage bot added PR: merged bot applied label for PR's that are merged and removed PR: partially-approved bot applied label for PR's where a single reviewer approves changes labels Oct 26, 2021
citizen428 pushed a commit that referenced this pull request Oct 29, 2021
…#15170)

* Initial work to expand detection functionality

* Finish up functionality and tests

* Fix class name

* Fix tests

* Update spec/services/articles/enrich_image_attributes_spec.rb

Co-authored-by: Michael Kohl <citizen428@forem.com>

* Update spec/services/articles/enrich_image_attributes_spec.rb

Co-authored-by: Michael Kohl <citizen428@forem.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: merged bot applied label for PR's that are merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants