This repository has been archived by the owner on Aug 4, 2022. It is now read-only.
Image dimension checker component in development #124
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was having trouble knowing the correct
width
andheight
props to put on the screenshots I was making for a blog post. I would take the screenshot and then use image tools and even a spreadsheet to figure out the right ratio/dimensions for how I wanted it to show up in the UI.If the
width
andheight
do not match the ratio of the actual image, it will become distorted, so that's a problem.This creates a component that wraps the
next/image
component. If thewidth
andheight
do not match the reality of the image, it shows a little red overlay (while in development). The banner uses the passed in dimensions to suggest changes that would match either the height or width.This is accomplished with a component that uses an API request. The server-side code seems to be needed to actually inspect the actual image on disk.
In this case, the component looked like this:
The component checked with the api
GET /api/imgdim?w=800&h=520&url=%2Fposts%2Fdeveloping-grouparoo-on-macos-big-sur%2Fbig-sur.jpg
Response:
This then showed in the UI, suggesting to make it either
800 x 534
or779 x 520
to fit the ratio.if
optimized
is true, the component doesn't show anything.