-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
feat: add crop support to image services #12414
Conversation
|
@@ -180,6 +180,60 @@ describe('astro:image:layout', () => { | |||
}); | |||
}); | |||
|
|||
describe('generated URLs', () => { |
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.
Github annotation says that logs
(line 19) is unused
/** @type {import('./test-utils').DevServer} */ | ||
let devServer; | ||
/** @type {Array<{ type: any, level: 'error', message: string; }>} */ | ||
let logs = []; |
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.
unused
|
||
describe('generated images', () => { | ||
let $; | ||
let src; |
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.
unused
* chore: changeset * feat: add experimental responsive images config option (#12378) * feat: add experimental responsive images config option * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <[email protected]> * Update config types * Move config into `images` * Move jsdocs --------- Co-authored-by: Sarah Rainsberger <[email protected]> * feat: add responsive image component (#12381) * feat: add experimental responsive images config option * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <[email protected]> * Update config types * Move config into `images` * Move jsdocs * wip: responsive image component * Improve srcset logic * Improve fixture * Lock * Update styling * Fix style prop handling * Update test (there's an extra style for images now) * Safely access the src props * Remove unused export * Handle priority images * Consolidate styles * Update tests * Comment * Refactor srcset * Avoid dupes of original image * Calculate missing dimensions * Bugfixes * Add tests * Fix test * Correct order * Lint * Fix fspath * Update test * Fix test * Conditional component per flag * Fix class concatenation * Remove logger * Rename helper * Add comments * Format * Fix markdoc tests * Add test for style tag --------- Co-authored-by: Sarah Rainsberger <[email protected]> * feat: add crop support to image services (#12414) * wip: add crop support to image services * Add tests * Strip crop attributes * Don't upscale * Format * Get build working properly * Changes from review * Fix jsdoc * feat: add responsive support to picture component (#12423) * feat: add responsive support to picture component * Add picture tests * Fix test * Implement own define vars * Share logic * Prevent extra astro-* class * Use dataset scoping * Revert unit test * Revert "Fix test" This reverts commit f9ec6e2. * Changes from review * docs: add docs for responsive images (#12429) * docs: add responsive images flag docs * docs: adds jsdoc for image components * chore: updates from review * Fix jsdoc * Changes from review * Add breakpoints option * typo --------- Co-authored-by: Sarah Rainsberger <[email protected]>
Changes
Adds new
fit
andposition
parameter toImageTransform
, which tells an image service how to handle images when the requested aspect ratio is different fromt he source. Currently if both width and height are set then height is ignored. Now iffit
is set then both are used, and cropping is enabled.fit
sets the behvior for an image service if the requested aspect ratio is different from the source image. Allowed values are CSSobject-fit
values, but it also accepts arbitrary strings that may be understood by a particular image service.postion
is used when cropping, to choose the point at which to focus the crop. It accepts CSSobject-position
values, but also allows arbitrary strings that may be supported by an image service. For example, the default sharp service supportentropy
for position, which focusses on the point with the most detail.This PR implements this crop support in the default sharp image service. It also changes the behaviour when fit is set to set
withoutEnlargement
, ensuring the service never returns images that are larger than the source. The styling in the image component means that if the smaller image is returned then the upscaling will happen in the browser, which is more efficient.Testing
The PR adds integration tests for the generation of srcsets. It also tests the actual image generation, ensuring the dimensions of the returned images are as expected.
Docs