I am trying to compress a CIImage below a certain file size threshold when creating a JPEG. Currently, I am handling this in, potentially, multiple passes. In the first pass, I am essentially calling: encodeJPEG(CIImage, quality: 0.85, colorSpace: CIImage.colorSpace ?? CGColorSpace(name: CGColorSpace.sRGB)!) I am then checking the image size. If the image is still too big, I try to estimate how much I need to reduce it and try again until the image size is small enough.
My question: Is there a more efficient way of doing this?