         encoder.iccData = iccData
         
         if let quality = properties[.compressionQuality] as? Double {
-            encoder.quality = 100 * quality
+            encoder.quality = (quality * 100).clamped(to: 0...100)
         }
         
         return encoder.encode()

        encoder.iccData = iccData
        
        if let quality = properties[.compressionQuality] as? Double {
            encoder.quality = 100 * quality
        }
        
        return encoder.encode()

            var buffer: UnsafeMutablePointer<UInt8>?
            let size = webp_encode(pixels, width, height, bytesPerRow, importer, quality ?? 100, quality == nil, &buffer)
            
            guard buffer != nil && size != 0 else { return nil }
            defer { WebPFree(buffer) }
            
            var image = WebPData(bytes: buffer, size: size)
            guard WebPMuxSetImage(mux, &image, 1) == WEBP_MUX_OK else { return nil }
