ericnograles / browser-image-resizer

A tiny browser-based library to downscale and/or resize images using canvas
MIT License
99 stars 43 forks source link

Add directions for static generation usage #77

Open bruceharrison1984 opened 1 year ago

bruceharrison1984 commented 1 year ago

When using this library for SSG scenarios like NextJS, it's necessary to use a dynamic import otherwise the build fails with self is not defined.

For NextJS, this looks like the following:

const { readAndCompressImage } = (await import('browser-image-resizer'));

This is because the static generation doesn't have access to the browser context. Otherwise it works great!

ericnograles commented 1 year ago

Great feedback, thanks @bruceharrison1984! I'll throw that in the README.md