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

misc: add usesPixelArtScaling flag to images #10481

Merged
merged 3 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lighthouse-core/gather/gatherers/image-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ function getHTMLImages(allElements) {
usesObjectFit: ['cover', 'contain', 'scale-down', 'none'].includes(
computedStyle.getPropertyValue('object-fit')
),
usesPixelArtScaling: ['pixelated', 'crisp-edges'].includes(
computedStyle.getPropertyValue('image-rendering')
),
// https://html.spec.whatwg.org/multipage/images.html#pixel-density-descriptor
usesSrcSetDensityDescriptor: / \d+(\.\d+)?x/.test(element.srcset),
};
});
}
Expand Down Expand Up @@ -95,6 +100,10 @@ function getCSSImages(allElements) {
isCss: true,
isPicture: false,
usesObjectFit: false,
usesPixelArtScaling: ['pixelated', 'crisp-edges'].includes(
style.getPropertyValue('image-rendering')
),
usesSrcSetDensityDescriptor: false,
resourceSize: 0, // this will get overwritten below
});
}
Expand Down
9 changes: 9 additions & 0 deletions types/artifacts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,15 @@ declare global {
isPicture: boolean;
/** Flags whether this element was sized using a non-default `object-fit` CSS property. */
usesObjectFit: boolean;
/** Flags whether this element was rendered using a pixel art scaling method.
* See https://developer.mozilla.org/en-US/docs/Games/Techniques/Crisp_pixel_art_look for
* details.
*/
usesPixelArtScaling: boolean;
/** Flags whether the image has a srcset with density descriptors.
* See https://html.spec.whatwg.org/multipage/images.html#pixel-density-descriptor
*/
usesSrcSetDensityDescriptor: boolean;
/** The size of the underlying image file in bytes. 0 if the file could not be identified. */
resourceSize: number;
/** The MIME type of the underlying image file. */
Expand Down