Skip to content

Instantly share code, notes, and snippets.

@turbulem
Last active November 12, 2018 16:35
Show Gist options
  • Select an option

  • Save turbulem/c819774cc3e05946caa895ec25fa0c92 to your computer and use it in GitHub Desktop.

Select an option

Save turbulem/c819774cc3e05946caa895ec25fa0c92 to your computer and use it in GitHub Desktop.
GifFile.swift
import Foundation
import GifSwift.CLibgif
public class GifFile {
private let path: URL
private let fileHandlePtr: UnsafeMutablePointer<GifFileType>
private var fileHandle: GifFileType {
return self.fileHandlePtr.pointee
}
deinit {
DGifCloseFile(self.fileHandlePtr, nil)
}
// MARK: - API
public init?(path: URL) {
self.path = path
let errorCode = UnsafeMutablePointer<Int32>.allocate(capacity: 1)
if let handle = path.path.withCString({ DGifOpenFileName($0, errorCode) }) {
self.fileHandlePtr = handle
DGifSlurp(handle)
} else {
debugPrint("Error opening file \(errorCode.pointee)")
return nil
}
}
public var size: CGSize {
return CGSize(width: Double(fileHandle.SWidth), height: Double(fileHandle.SHeight))
}
public var imagesCount: Int {
return Int(fileHandle.ImageCount)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment