title: UIImage resizing scale
body: <p>I have an image like this:</p>
  
  <p><img src="https://i.stack.imgur.com/oAsy8m.jpg" alt="Have a look at this image"></p>
  
  <p>and I'd like to resize this image to a specific width: <strong>let's say 200px</strong> where the height should also get calculated. (So the image should keep its width-to-height scale)</p>
  
  <p>This was all I get so far:</p>
  
  <pre><code>extension UIImage {
      func resize(newSize1: CGSize) -&gt; UIImage {
          let size = self.size
          let widthRatio  = newSize1.width  / size.width
          let heightRatio = newSize1.height / size.height
  
          var newSize2: CGSize
          if(widthRatio &gt; heightRatio) {
              newSize2 = CGSize(width: size.width * heightRatio, height: size.height * heightRatio)
          } else {
              newSize2 = CGSize(width: size.width * widthRatio,  height: size.height * widthRatio)
          }
          let rect = CGRect(x: 0, y: 0, width: newSize2.width, height: newSize2.height)
          UIGraphicsBeginImageContextWithOptions(newSize2, false, 1.0)
          self.draw(in: rect)
          let newImage = UIGraphicsGetImageFromCurrentImageContext()
          UIGraphicsEndImageContext()
          return newImage2!
      }
  }
  </code></pre>
  
  <p>But the function takes a <code>CGSize</code> size parameter (width AND height) but I just want to get a function that takes the width parameter.</p>
  
  <p>How to edit my code to solve my problem?<br>
  Any help would be very appreciated <code>:)</code></p>
  
  <p><strong>Note</strong>: The UIImage should get a smaller resolution (less pixels), not the Image View itself! </p>