Skip to content

Commit

Permalink
change HEIF convert PNG -> JPG
Browse files Browse the repository at this point in the history
  • Loading branch information
wade.hawk committed May 11, 2018
1 parent 821efef commit f00b580
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Example/TLPhotoPicker/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ViewController: UIViewController,TLPhotosPickerViewControllerDelegate {

func getAsyncCopyTemporaryFile() {
if let asset = self.selectedAssets.first {
asset.tempCopyMediaFile(convertLivePhotosToPNG: false, progressBlock: { (progress) in
asset.tempCopyMediaFile(convertLivePhotosToJPG: false, progressBlock: { (progress) in
print(progress)
}, completionBlock: { (url, mimeType) in
print("completion\(url)")
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public struct TLPHAsset {
// parmeter : convertLivePhotosToPNG
// false : If you want mov file at live photos
// true : If you want png file at live photos ( HEIC )
public func tempCopyMediaFile(videoRequestOptions: PHVideoRequestOptions? = nil, imageRequestOptions: PHImageRequestOptions? = nil, exportPreset: String = AVAssetExportPresetHighestQuality, convertLivePhotosToPNG: Bool = false, progressBlock:((Double) -> Void)? = nil, completionBlock:@escaping ((URL,String) -> Void)) -> PHImageRequestID?
public func tempCopyMediaFile(videoRequestOptions: PHVideoRequestOptions? = nil, imageRequestOptions: PHImageRequestOptions? = nil, exportPreset: String = AVAssetExportPresetHighestQuality, convertLivePhotosToJPG: Bool = false, progressBlock:((Double) -> Void)? = nil, completionBlock:@escaping ((URL,String) -> Void)) -> PHImageRequestID?
//Apparently, this method is not be safety to export a video.
//There is many way that export a video.
//This method was one of them.
Expand Down
2 changes: 1 addition & 1 deletion TLPhotoPicker.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'TLPhotoPicker'
s.version = '1.6.6'
s.version = '1.6.7'
s.summary = 'multiple phassets picker for iOS lib. like facebook'

# This description is used to generate tags and improve search results.
Expand Down
12 changes: 6 additions & 6 deletions TLPhotoPicker/Classes/TLAssetsCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ public struct TLPHAsset {
//convertLivePhotosToPNG
// false : If you want mov file at live photos
// true : If you want png file at live photos ( HEIC )
public func tempCopyMediaFile(videoRequestOptions: PHVideoRequestOptions? = nil, imageRequestOptions: PHImageRequestOptions? = nil, exportPreset: String = AVAssetExportPresetHighestQuality, convertLivePhotosToPNG: Bool = false, progressBlock:((Double) -> Void)? = nil, completionBlock:@escaping ((URL,String) -> Void)) -> PHImageRequestID? {
public func tempCopyMediaFile(videoRequestOptions: PHVideoRequestOptions? = nil, imageRequestOptions: PHImageRequestOptions? = nil, exportPreset: String = AVAssetExportPresetHighestQuality, convertLivePhotosToJPG: Bool = false, progressBlock:((Double) -> Void)? = nil, completionBlock:@escaping ((URL,String) -> Void)) -> PHImageRequestID? {
guard let phAsset = self.phAsset else { return nil }
var type: PHAssetResourceType? = nil
if phAsset.mediaSubtypes.contains(.photoLive) == true, convertLivePhotosToPNG == false {
if phAsset.mediaSubtypes.contains(.photoLive) == true, convertLivePhotosToJPG == false {
type = .pairedVideo
}else {
type = phAsset.mediaType == .video ? .video : .photo
Expand All @@ -156,10 +156,10 @@ public struct TLPHAsset {
} else {
writeURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true).appendingPathComponent("\(fileName)")
}
if (writeURL?.pathExtension.uppercased() == "HEIC" || writeURL?.pathExtension.uppercased() == "HEIF") && convertLivePhotosToPNG {
if (writeURL?.pathExtension.uppercased() == "HEIC" || writeURL?.pathExtension.uppercased() == "HEIF") && convertLivePhotosToJPG {
if let fileName2 = writeURL?.deletingPathExtension().lastPathComponent {
writeURL?.deleteLastPathComponent()
writeURL?.appendPathComponent("\(fileName2).png")
writeURL?.appendPathComponent("\(fileName2).jpg")
}
}
guard let localURL = writeURL,let mimetype = MIMEType(writeURL) else { return nil }
Expand Down Expand Up @@ -202,8 +202,8 @@ public struct TLPHAsset {
return PHImageManager.default().requestImageData(for: phAsset, options: requestOptions, resultHandler: { (data, uti, orientation, info) in
do {
var data = data
if convertLivePhotosToPNG == true, let imgData = data, let rawImage = UIImage(data: imgData)?.upOrientationImage() {
data = UIImagePNGRepresentation(rawImage)
if convertLivePhotosToJPG == true, let imgData = data, let rawImage = UIImage(data: imgData)?.upOrientationImage() {
data = UIImageJPEGRepresentation(rawImage, 1)
}
try data?.write(to: localURL)
DispatchQueue.main.async {
Expand Down

0 comments on commit f00b580

Please sign in to comment.