mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Refactor PasswordSetupUI, PassportUI, GalleryUI and related modules
This commit is contained in:
19
submodules/ImageCompression/Sources/ImageCompression.h
Normal file
19
submodules/ImageCompression/Sources/ImageCompression.h
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// ImageCompression.h
|
||||
// ImageCompression
|
||||
//
|
||||
// Created by Peter on 8/12/19.
|
||||
// Copyright © 2019 Telegram Messenger LLP. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
//! Project version number for ImageCompression.
|
||||
FOUNDATION_EXPORT double ImageCompressionVersionNumber;
|
||||
|
||||
//! Project version string for ImageCompression.
|
||||
FOUNDATION_EXPORT const unsigned char ImageCompressionVersionString[];
|
||||
|
||||
// In this header, you should import all the public headers of your framework using statements like #import <ImageCompression/PublicHeader.h>
|
||||
|
||||
|
||||
48
submodules/ImageCompression/Sources/ImageCompression.swift
Normal file
48
submodules/ImageCompression/Sources/ImageCompression.swift
Normal file
@@ -0,0 +1,48 @@
|
||||
import Foundation
|
||||
import AVFoundation
|
||||
import UIKit
|
||||
|
||||
public func compressImageToJPEG(_ image: UIImage, quality: Float) -> Data? {
|
||||
let data = NSMutableData()
|
||||
guard let destination = CGImageDestinationCreateWithData(data as CFMutableData, "public.jpeg" as CFString, 1, nil) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let options = NSMutableDictionary()
|
||||
options.setObject(quality as NSNumber, forKey: kCGImageDestinationLossyCompressionQuality as NSString)
|
||||
|
||||
guard let cgImage = image.cgImage else {
|
||||
return nil
|
||||
}
|
||||
CGImageDestinationAddImage(destination, cgImage, options as CFDictionary)
|
||||
CGImageDestinationFinalize(destination)
|
||||
|
||||
if data.length == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return data as Data
|
||||
}
|
||||
|
||||
@available(iOSApplicationExtension 11.0, iOS 11.0, *)
|
||||
public func compressImage(_ image: UIImage, quality: Float) -> Data? {
|
||||
let data = NSMutableData()
|
||||
guard let destination = CGImageDestinationCreateWithData(data as CFMutableData, AVFileType.heic as CFString, 1, nil) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let options = NSMutableDictionary()
|
||||
options.setObject(quality as NSNumber, forKey: kCGImageDestinationLossyCompressionQuality as NSString)
|
||||
|
||||
guard let cgImage = image.cgImage else {
|
||||
return nil
|
||||
}
|
||||
CGImageDestinationAddImage(destination, cgImage, options as CFDictionary)
|
||||
CGImageDestinationFinalize(destination)
|
||||
|
||||
if data.length == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return data as Data
|
||||
}
|
||||
Reference in New Issue
Block a user