title: Problems on Encode/Decode UIImage in base64 uploading/downloading
body: <p>I'm working in a project with PHP backend and an Swift app where, in backend I upload an image and then, from Swift app I download it. In the Swift app I have the possibility to upload image, remove the old image in the backend and save the new, similar to the facebook profile picture.</p>
  
  <p>Right now, I take the base64 string from the API of backend, I convert to UIImage and it works with this code: </p>
  
  <pre><code>let data: NSData = NSData(base64EncodedString: "string from API", options: NSDataBase64DecodingOptions(rawValue: 0))
  
  var img: UIImage = UIImage(data: data!)!
  </code></pre>
  
  <p>When I take a photo in Swift app, from Gallery or from cam, I try to encode the image and upload with the API. The first thing I don't understand is why when I codified the image, the length of the String generated is the double, more or less, of the String from API when I take the image from the backend. </p>
  
  <p>I try to download the image from the backend and upload the same image to see if the string generated in base64 is the same, but not.</p>
  
  <p>This is what I make for encode the image form Swift app:</p>
  
  <pre><code>let img: NSData = UIImageJPEGRepresentation(MyImage.image, 1.0)!
  
  let base64Image: String = img.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
  </code></pre>
  
  <p>In PHP I use base64_encode(string) but the file generated is damaged or illegible.</p>