Skip to content

Commit

Permalink
not working yep_progressiveImage
Browse files Browse the repository at this point in the history
  • Loading branch information
nixzhu committed Jan 27, 2016
1 parent 4c03198 commit 50bd136
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
48 changes: 48 additions & 0 deletions Yep/Extensions/UIImage+Yep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import UIKit
import Ruler
import ImageIO
import MobileCoreServices

extension UIImage {

Expand Down Expand Up @@ -572,3 +574,49 @@ extension UIImage {
}
}

// MARK: Progressive

extension UIImage {

var yep_progressiveImage: UIImage? {

guard let cgImage = CGImage else {
return nil
}

let data = NSMutableData()

guard let distination = CGImageDestinationCreateWithData(data, kUTTypeJPEG, 1, nil) else {
return nil
}

let jfifProperties = [
kCGImagePropertyJFIFIsProgressive as String: kCFBooleanTrue as Bool,
kCGImagePropertyJFIFXDensity as String: 72,
kCGImagePropertyJFIFYDensity as String: 72,
kCGImagePropertyJFIFDensityUnit as String: 1,
]

let properties = [
kCGImageDestinationLossyCompressionQuality as String: 0.9,
kCGImagePropertyJFIFDictionary as String: jfifProperties,
]

CGImageDestinationAddImage(distination, cgImage, properties)

guard CGImageDestinationFinalize(distination) else {
return nil
}

guard data.length > 0 else {
return nil
}

guard let progressiveImage = UIImage(data: data) else {
return nil
}

return progressiveImage
}
}

3 changes: 1 addition & 2 deletions Yep/Services/YepDownloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,7 @@ extension YepDownloader: NSURLSessionDataDelegate {
/*
if progressReporter.totalProgress > 0.3 {
print("imageTransform")
}
*/
}*/
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4633,6 +4633,14 @@ extension ConversationViewController: UIImagePickerControllerDelegate, UINavigat
// Do send

let imageData = UIImageJPEGRepresentation(image, YepConfig.messageImageCompressionQuality())!
/*
var imageData = UIImageJPEGRepresentation(image, YepConfig.messageImageCompressionQuality())!
if let progressiveImage = UIImage(data: imageData)?.yep_progressiveImage {
imageData = UIImageJPEGRepresentation(progressiveImage, YepConfig.messageImageCompressionQuality())!
}
*/

let messageImageName = NSUUID().UUIDString

Expand Down

0 comments on commit 50bd136

Please sign in to comment.