func useLossless(image *vips.Image, options SaveOptions) bool { if !options.Lossless { return false } if !options.LossyIfPhoto { return true } // Mobile devices start being unwilling to load >= 3 megapixel PNGs. // Also we don't want to bother to edge detect on large images. if image.Xsize()*image.Ysize() >= 3*1024*1024 { return false } // Take a histogram of a Sobel edge detect of our image. What's the // highest number of histogram values in a row that are more than 1% // of the maximum value? Above 16 indicates a photo. metric, err := image.PhotoMetric(0.01) return err != nil || metric < 16 }