Skip to content

fix: refactor image function #317

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 1 commit into from
May 18, 2021
Merged

fix: refactor image function #317

merged 1 commit into from
May 18, 2021

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented May 17, 2021

This is a rewrite of the image function. The main fixes are improved error handling and new logic to determine output format. The logic for choosing the output format is as follows:

  1. Determine the format of the input image by examining the buffer
  2. If the format is SVG or GIF then we do not process it at all, so we redirect to the source image
  3. If the format is unsupported (i.e. not JPEG, PNG, WebP or AVIF) then we fall-back to JPEG output
  4. If the env var FORCE_WEBP_OUTPUT is set, then set output format to WebP.
  5. Otherwise, output format is the same as input format.
    Fixes Support for GIF and SVG in next/image #307 and [next_image] Fails to load most of JPG images. (Input buffer contains unsupported image format) #312

@github-actions github-actions bot added the type: bug code to address defects in shipped code label May 17, 2021
Copy link

@lindsaylevine lindsaylevine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing!!!!!!! i think this might also fix #133 which i forgot about until i saw the env var?! just added the label to it - lmk what you think and/or comment on it if you see fit!!!


let { ext } = type

// For unsupported formats (gif, svg) we redirect to the original

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

}

// The format methods are just to set options: they don't
// make it return that format.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh huh ok!!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for GIF and SVG in next/image
2 participants