title: how to reduce size of the image in swift ios
body: <p>I want to reduce the size of image like this website
  <a href="http://resizeimage.net" rel="nofollow noreferrer">http://resizeimage.net</a>
  my image is 1080 x 360 size 120kb after I used the code below 
  but when I use the website I get 58kb
  or if there is a library or algorithm to compress JPEG file</p>
  
  <pre><code>func resizeImage(_ image: UIImage, newHeight: CGFloat) -&gt; UIImage {
      let scale = newHeight / image.size.height
      let newWidth = image.size.width * scale
      UIGraphicsBeginImageContext(CGSize(width: newWidth, height: newHeight))
      image.draw(in: CGRect(x: 0, y: 0, width: newWidth, height: newHeight))
      let newImage = UIGraphicsGetImageFromCurrentImageContext()
      let imageData = UIImageJPEGRepresentation(newImage!, 0.5)! as Data
      UIGraphicsEndImageContext()
      return UIImage(data:imageData)!
  }
  </code></pre>