Here's an open source, self-hosted one, that should be easy to integrate with Next.js:
https://github.com/willnorris/imageproxy
To define a custom one, you need only provide a function:
https://nextjs.org/docs/api-reference/next/image#loader