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

gif formats are not supported #5453

Closed
wants to merge 7 commits into from
Closed
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/gentle-clouds-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/image': minor
---

gif formats are not supported
8 changes: 7 additions & 1 deletion packages/integrations/image/src/build/ssg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,13 @@ export async function ssgBuild({

// a valid cache file wasn't found, transform the image and cache it
if (!data) {
const transformed = await loader.transform(inputBuffer, transform);
let transformed;
if (transform.src.includes('.gif')) {
const gifLoader = await (await import('../loaders/sharp.js')).default;
transformed = await gifLoader.transform(inputBuffer, transform);
} else {
transformed = await loader.transform(inputBuffer, transform);
}
data = transformed.data;

// cache the image, if available
Expand Down
15 changes: 10 additions & 5 deletions packages/integrations/image/src/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,20 @@ export const get: APIRoute = async ({ request }) => {
if (!inputBuffer) {
return new Response('Not Found', { status: 404 });
}
let transformed;
if (transform.src.includes('.gif')) {
const gifLoader = await (await import('./loaders/sharp.js')).default;
transformed = await gifLoader.transform(inputBuffer, transform);
} else {
transformed = await loader.transform(inputBuffer, transform);
}

const { data, format } = await loader.transform(inputBuffer, transform);

return new Response(data, {
return new Response(transformed.data, {
status: 200,
headers: {
'Content-Type': mime.getType(format) || '',
'Content-Type': mime.getType(transformed.format) || '',
'Cache-Control': 'public, max-age=31536000',
ETag: etag(data.toString()),
ETag: etag(transformed.data.toString()),
Date: new Date().toUTCString(),
},
});
Expand Down