title: Compressing image taken from device or chosen from library, iOS
body: <p>In my app, user is allowed to take a photo from a device or upload it from the library to set it as his profile pic. Now when user is done, I need to upload that image to server. Usually the image taken from device is of size 5-6MB. I need it to compress to 25KB before uploading to server. So I am using following method to that</p>
  
  <pre><code>- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
      [picker dismissModalViewControllerAnimated:YES];
      [picker release];
      profilePicImageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
      NSData* pngData = UIImagePNGRepresentation(profilePicImageView.image);
      NSLog(@"image size of png is %d", [pngData length]);
      NSData *imageData = UIImageJPEGRepresentation(profilePicImageView.image, 0.00001);
      NSLog(@"image size is %d", [imageData length]);
  }
  </code></pre>
  
  <p>Problem with this method is, no matter how small I set the scaling parameter, compressed file size does not drop below ~230KB, which is nearly 10 times higher than what I need.</p>
  
  <p>What is wrong with the above method? Can't I compress image to 25KB?</p>
  
  <p>Any help, suggestion will be greatly appreciated.</p>