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

Support AVIF input assets #8380

Merged
merged 10 commits into from
Sep 11, 2023
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
5 changes: 5 additions & 0 deletions .changeset/five-doors-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Support AVIF input assets
4 changes: 4 additions & 0 deletions packages/astro/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ declare module '*.svg' {
const metadata: ImageMetadata;
export default metadata;
}
declare module '*.avif' {
const metadata: ImageMetadata;
export default metadata;
}

declare module 'astro:transitions' {
type TransitionModule = typeof import('./dist/transitions/index.js');
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
"p-limit": "^4.0.0",
"path-to-regexp": "^6.2.1",
"preferred-pm": "^3.1.2",
"probe-image-size": "^7.2.3",
"prompts": "^2.4.2",
"rehype": "^12.0.1",
"resolve": "^1.22.4",
Expand Down Expand Up @@ -197,6 +198,7 @@
"@types/js-yaml": "^4.0.5",
"@types/mime": "^3.0.1",
"@types/mocha": "^10.0.1",
"@types/probe-image-size": "^7.2.0",
"@types/prompts": "^2.4.4",
"@types/resolve": "^1.20.2",
"@types/send": "^0.17.1",
Expand Down
10 changes: 2 additions & 8 deletions packages/astro/src/assets/consts.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
export const VIRTUAL_MODULE_ID = 'astro:assets';
export const VIRTUAL_SERVICE_ID = 'virtual:image-service';
export const VALID_INPUT_FORMATS = [
// TODO: `image-size` does not support the following formats, so users can't import them.
// However, it would be immensely useful to add, for three reasons:
// - `heic` and `heif` are common formats, especially among Apple users.
// - AVIF is a common format on the web that's bound to become more and more common.
// - It's totally reasonable for an user's provided image service to want to support more image types.
//'heic',
//'heif',
//'avif',
'jpeg',
'jpg',
'png',
'tiff',
'webp',
'gif',
'svg',
'avif',
] as const;
/**
* Valid formats that our base services support.
Expand All @@ -29,5 +22,6 @@ export const VALID_SUPPORTED_FORMATS = [
'webp',
'gif',
'svg',
'avif',
] as const;
export const VALID_OUTPUT_FORMATS = ['avif', 'png', 'webp', 'jpeg', 'jpg', 'svg'] as const;
9 changes: 7 additions & 2 deletions packages/astro/src/assets/utils/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import type { ImageInputFormat, ImageMetadata } from '../types.js';
import imageSize from '../vendor/image-size/index.js';
import probe from 'probe-image-size';

export async function imageMetadata(data: Buffer): Promise<Omit<ImageMetadata, 'src'> | undefined> {
const { width, height, type, orientation } = imageSize(data);
const result = probe.sync(data);
if (result === null) {
throw new Error('Failed to probe image size.');
}

const { width, height, type, orientation } = result;
const isPortrait = (orientation || 0) >= 5;

if (!width || !height || !type) {
Expand Down
3 changes: 0 additions & 3 deletions packages/astro/src/assets/vendor/README.md

This file was deleted.

9 changes: 0 additions & 9 deletions packages/astro/src/assets/vendor/image-size/LICENSE

This file was deleted.

30 changes: 0 additions & 30 deletions packages/astro/src/assets/vendor/image-size/detector.ts

This file was deleted.

146 changes: 0 additions & 146 deletions packages/astro/src/assets/vendor/image-size/index.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/astro/src/assets/vendor/image-size/readUInt.ts

This file was deleted.

38 changes: 0 additions & 38 deletions packages/astro/src/assets/vendor/image-size/types.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/astro/src/assets/vendor/image-size/types/bmp.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/astro/src/assets/vendor/image-size/types/cur.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/astro/src/assets/vendor/image-size/types/dds.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/astro/src/assets/vendor/image-size/types/gif.ts

This file was deleted.

Loading
Loading