Skip to content

Instantly share code, notes, and snippets.

@AngelKrak
Created February 14, 2024 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AngelKrak/38ac2fee64888602d966e15288fe80b0 to your computer and use it in GitHub Desktop.
Save AngelKrak/38ac2fee64888602d966e15288fe80b0 to your computer and use it in GitHub Desktop.
getImage by Weserv
const imageUrl = (url, opts) =>
`https://wsrv.nl/?${new URLSearchParams({
/* The image URL to optimize */
url,
/* In case something goes wrong, just show the image */
default: url,
/*
Compress it as much as possible (PNG).
See: https://images.weserv.nl/docs/format.html#compression-level
*/
l: 9,
/*
Reduce PNG file size.
See: https://images.weserv.nl/docs/format.html#adaptive-filter
*/
af: '',
/*
Enable image optimization for GIF and JPEG.
See: https://images.weserv.nl/docs/format.html#interlace-progressive
*/
il: '',
/*
Enable image optimization for WebP and GIF.
See: https://images.weserv.nl/docs/format.html#number-of-pages
*/
n: -1,
/*
Pass any other option.
See https://images.weserv.nl/docs/quick-reference.html
It's recommended to pass `w` for cutting down the image size.
*/
...opts
}).toString()}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment