Currently the jpeg.Encode() checks if the size of the image.Image passed to it is smaller than 1<<16 in either dimension.
We often work with images up to 1<<20 pixels wide.
Our current solution is to patch the go source code before build to remove this check.
This solution works fine on amd64, I don't know if this restriction is mean to protect systems with lower memory or is just a sanity check.
Proposal: modify the line lined below to allow images as large as 1<<21
https://cs.opensource.google/go/go/+/refs/tags/go1.18:src/image/jpeg/writer.go;drc=35cbc3b55b9d5d159a5a7a160ea680b32f043bf8;l=577