再生礼
在 iOS 和 macOS 上轻松将视频转换为 GIF。
我还制作了 Rocket,一个在您的 Mac 上提供 Slack 风格表情的应用程序。
要求
- Xcode 10+
- iOS 11.1+ / macOS 10.12+
- Swfit 5.0+
安装
Cocoapods
再生礼通过 CocoaPods 提供。要安装它,只需在 Podfile 中添加以下行:
pod "Regift"
Carthage
可以通过Carthage进行Regift。
github 'matthewpalmer/Regift'
快速入门
import Regift
同步GIF创建
let videoURL = ...
let frameCount = 16
let delayTime = Float(0.2)
let loopCount = 0 // 0 means loop forever
let regift = Regift(sourceFileURL: videoURL, frameCount: frameCount, delayTime: delayTime, loopCount: loopCount)
print("Gif saved to \(regift.createGif())")
let startTime = Float(30)
let duration = Float(15)
let frameRate = 15
let trimmedRegift = Regift(sourceFileURL: URL, startTime: startTime, duration: duration, frameRate: frameRate, loopCount: loopCount)
print("Gif saved to \(trimmedRegift.createGif())")
异步GIF创建
let videoURL = ...
let frameCount = 16
let delayTime = Float(0.2)
let loopCount = 0 // 0 means loop forever
Regift.createGIFFromSource(videoURL, frameCount: frameCount, delayTime: delayTime) { (result) in
print("Gif saved to \(result)")
}
let startTime = Float(30)
let duration = Float(15)
let frameRate = 15
Regift.createGIFFromSource(videoURL, startTime: startTime, duration: duration, frameRate: frameRate) { (result) in
print("Gif saved to \(result)")
}
致谢
感谢Rob Mayoff的Gist,没有它,这个库就不会存在。
向所有Regift的贡献者个人致谢
- caughtinflux
- samuelbeek
- sebyddd
- nakajijapan
- dbburgess