title: How to convert a PNG to a WebP in Swift?
body: <p>I'm trying to convert a PNG image in Webp in Swift, the only framework I got working is <strong>OpenCV</strong> through <em>Objective-c++</em>. <br> The problem is that if I resize the image by 512x512 (that's the resolution I need) it crashes:
  <a href="https://i.stack.imgur.com/Ti30I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ti30I.png" alt="enter image description here"></a>
  If I resize the image (either with OpenCV either with Swift) to another resolution (ex 510x510) it doesn't crash. </p>
  
  <p>The strange thing is that on the simulator it never crashes while on the iPhone XS it crashes 90% of the times. <br><br>How can I convert a PNG to a Webp in Swift? <br>Why is OpenCV crashing on the <em>imwrite</em> instruction if the Mat is 512x512?</p>
  
  <p><strong>UPDATE</strong>:
  <br> OpenCV version: 3.4.2<br>
  I found out that this problem happens when the PNG image get processed before from the Core Graphics framework. I need to use it since I save a UIVIew as UIImage this way:</p>
  
  <pre><code>let renderer = UIGraphicsImageRenderer(bounds: bounds)
          return renderer.image { rendererContext in
              layer.render(in: rendererContext.cgContext)
          }
  </code></pre>