This framework is based on the Android NDK GIF Library, forked and hooked up as a submodule, that can be found here.
Small adjustments to the C++
code have been made to make it compilable as Objective-C++
.
The project currently only supports encoding. But with little effort decoding can also be added. Two modes are available:
- ENCODING_TYPE_SIMPLE_FAST
- ENCODING_TYPE_NORMAL_LOW_MEMORY
The original project also includes ENCODING_TYPE_STABLE_HIGH_MEMORY but currently there are some problems with it.
Example usgae can be found in the GIFExample project:
...
var encoder: GIFEncoder? = nil
for path in paths {
guard let image = UIImage(contentsOfFile: path) else {
print("Could not acquire image at path \(path)")
continue
}
if encoder == nil {
encoder = GIFEncoder(mode: .NormalLowMemory, width: UInt(image.size.width), height: UInt(image.size.height), filePath: gifPath)
}
do {
try encoder?.encodeFrame(image, frameDelay: 250)
} catch {
print("Could not create frame for image at path \(path)")
}
}
encoder?.closeGif()