dc7290 / next-export-optimize-images

Optimize images at build time with Next.js.
https://next-export-optimize-images.vercel.app
MIT License
385 stars 35 forks source link

Support converting + optimizing SVGs to other image formats #878

Open johnpyp opened 4 months ago

johnpyp commented 4 months ago

Is your feature request related to a problem? Please describe. SVGs are often used as the highest-fidelity exports from things like Figma - even a lossless image export doesn't really match the quality of an SVG because it can be forever-scaled up while being the same fidelity. For that reason, we try to use SVGs as the source image in source-code too.

However, next-export-optimize-images doesn't currently support optimizing svgs to other file formats like avif/webp (seems like due to https://github.com/dc7290/next-export-optimize-images/pull/658)

Describe the solution you'd like A clear and concise description of what you want to happen. It would be great if the library supported optimizing SVGs, actually the opposite of https://github.com/dc7290/next-export-optimize-images/pull/658. NextJS now supports this with a flag https://nextjs.org/docs/app/api-reference/components/image#dangerouslyallowsvg

Describe alternatives you've considered Pre-processing the SVGs to an intermediate format - but this kind of defeats the whole purpose of the automatic optimization in the first place :)

Additional context N/A

dc7290 commented 4 months ago

I see. As a feature request, do you want to "change SVG images to AVIF or WEBP format when you specify them"?

dc7290 commented 3 months ago

Incidentally, I think Next.js also just returns the buffer as it is without any optimisation for vector images like SVG. https://github.com/vercel/next.js/blob/canary/packages/next/src/server/image-optimizer.ts#L594 I'm not sure what you mean by optimising SVG, but I think Figma, for example, can output without extra tags and IDs, so you might want to try using that.