Skip to content

Latest commit

 

History

History
67 lines (50 loc) · 1.7 KB

README.md

File metadata and controls

67 lines (50 loc) · 1.7 KB

libminipng

通过lodepng解析png图片,使用pngquant算法进行压缩的swift-framework

方法说明:

/// 通过PNG图片Data压缩
///
/// - Parameters:
///   - data: PNG图片Data
///   - maximum: 压缩率,0-100,100为最好
/// - Returns: 压缩后的PNG图片Data
public static func data2Data(_ data:Data,_ maximum:Int) -> Data?
/// 通过PNG图片路径压缩
///
/// - Parameters:
///   - path: PNG图片路径
///   - maximum: 压缩率,0-100,100为最好
/// - Returns: 压缩后的PNG图片Data
public static func path2Data(_ path:String,_ maximum:Int) -> Data?

Cocoapods

Podfile 添加 pod "libminipng"

运行命令 pod install

使用

引入 import libminipng

编写代码:

let path:String = "http://images.ichochy.com/Cloud.png"
let data:Data = try! Data.init(contentsOf: URL.init(string: path)!)
let maximum:Int = 100 // 压缩率,0-100,100为最好
let result:Data? = minipng.data2Data(data,maximum)
try! result?.write(to: URL.init(fileURLWithPath: "/Users/mleo/minipng.png"))
let path:String = "/Users/mleo/Cloud.png"
let maximum:Int = 100 // 压缩率,0-100,100为最好
let result:Data? = minipng.path2Data(path, maximum)
try! result?.write(to: URL.init(fileURLWithPath: "/Users/mleo/minipng.png"))

GitHub:

libminipng: https://github.com/iChochy/libminipng
pngquant: https://github.com/ImageOptim/libimagequant
lodepng: https://github.com/lvandeve/lodepng


联系方系:

邮箱:[email protected]
网站:https://libminipng.ichochy.com
GitHub: https://github.com/iChochy