Skip to content

fix: disable png palette #525

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

Merged
merged 4 commits into from
Jul 13, 2021
Merged
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
20 changes: 3 additions & 17 deletions src/lib/templates/imageFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const handler = async (event) => {
} else {
isRemoteImage = true
// Remote images need to be in the allowlist
let allowedDomains = config.images?.domains || []
let allowedDomains = config.domains || []

if (process.env.NEXT_IMAGE_ALLOWED_DOMAINS) {
console.log('Combining `NEXT_IMAGE_ALLOWED_DOMAINS` with any domains found in `next.config.js`')
Expand Down Expand Up @@ -84,20 +84,6 @@ const handler = async (event) => {
return { statusCode: 400, body: 'Source does not appear to be an image' }
}

const dimensions = imageSize(bufferData)

if (width > dimensions.width) {
// We won't upsize images, and to avoid downloading the same size multiple times,
// we redirect to the largest available size
const Location = `/nextimg/${url}/${dimensions.width}/${q}`
return {
statusCode: 302,
headers: {
Location,
},
}
}

let { ext } = type

// For unsupported formats (gif, svg) we redirect to the original
Expand All @@ -122,8 +108,8 @@ const handler = async (event) => {
// make it return that format.
const { info, data: imageBuffer } = await sharp(bufferData)
.rotate()
.jpeg({ quality, mozjpeg: true, force: ext === 'jpg' })
.png({ quality, palette: true, force: ext === 'png' })
.jpeg({ quality, force: ext === 'jpg' })
.png({ quality, force: ext === 'png' })
.webp({ quality, force: ext === 'webp' })
.avif({ quality, force: ext === 'avif' })
.resize(width, null, { withoutEnlargement: true })
Expand Down