{"id":21373683,"url":"https://github.com/SDWebImage/SDWebImageWebPCoder","last_synced_at":"2025-07-13T08:30:33.667Z","repository":{"id":37752301,"uuid":"146433595","full_name":"SDWebImage/SDWebImageWebPCoder","owner":"SDWebImage","description":"A WebP coder plugin for SDWebImage, use libwebp","archived":false,"fork":false,"pushed_at":"2024-04-17T09:15:17.000Z","size":4504,"stargazers_count":247,"open_issues_count":10,"forks_count":91,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-07-11T14:26:32.669Z","etag":null,"topics":["animated-webp","carthage","cocoapods","ios","macos","sdwebimage","tvos","watchos","webp"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SDWebImage.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-28T10:54:48.000Z","updated_at":"2025-07-09T13:46:59.000Z","dependencies_parsed_at":"2023-02-19T08:45:50.446Z","dependency_job_id":"fd3da8b0-8179-4b8a-b10b-3701c67a679b","html_url":"https://github.com/SDWebImage/SDWebImageWebPCoder","commit_stats":{"total_commits":169,"total_committers":9,"mean_commits":18.77777777777778,"dds":"0.12426035502958577","last_synced_commit":"f534cfe830a7807ecc3d0332127a502426cfa067"},"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"purl":"pkg:github/SDWebImage/SDWebImageWebPCoder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDWebImage%2FSDWebImageWebPCoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDWebImage%2FSDWebImageWebPCoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDWebImage%2FSDWebImageWebPCoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDWebImage%2FSDWebImageWebPCoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SDWebImage","download_url":"https://codeload.github.com/SDWebImage/SDWebImageWebPCoder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDWebImage%2FSDWebImageWebPCoder/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265066355,"owners_count":23706084,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["animated-webp","carthage","cocoapods","ios","macos","sdwebimage","tvos","watchos","webp"],"created_at":"2024-11-22T08:29:27.989Z","updated_at":"2025-07-13T08:30:33.638Z","avatar_url":"https://github.com/SDWebImage.png","language":"Objective-C","readme":"# SDWebImageWebPCoder\n\n[![CI Status](http://img.shields.io/travis/SDWebImage/SDWebImageWebPCoder.svg?style=flat)](https://travis-ci.org/SDWebImage/SDWebImageWebPCoder)\n[![Version](https://img.shields.io/cocoapods/v/SDWebImageWebPCoder.svg?style=flat)](http://cocoapods.org/pods/SDWebImageWebPCoder)\n[![License](https://img.shields.io/cocoapods/l/SDWebImageWebPCoder.svg?style=flat)](http://cocoapods.org/pods/SDWebImageWebPCoder)\n[![Platform](https://img.shields.io/cocoapods/p/SDWebImageWebPCoder.svg?style=flat)](http://cocoapods.org/pods/SDWebImageWebPCoder)\n[![SwiftPM compatible](https://img.shields.io/badge/SwiftPM-compatible-brightgreen.svg?style=flat)](https://swift.org/package-manager/)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/SDWebImage/SDWebImageWebPCoder)\n[![codecov](https://codecov.io/gh/SDWebImage/SDWebImageWebPCoder/branch/master/graph/badge.svg)](https://codecov.io/gh/SDWebImage/SDWebImageWebPCoder)\n\nStarting with the SDWebImage 5.0 version, we moved the WebP support code and [libwebp](https://github.com/webmproject/libwebp) from the Core Repo to this stand-alone repo.\n\nSDWebImageWebPCoder supports both WebP decoding and encoding, for Static WebP or Animated WebP as well.\n\nNote: Apple's ImageIO supports WebP decoding from iOS 14/tvOS 14/watchOS 7/macOS 11, so SDWebImage on those platform can also decode WebP images (using `SDWebImageAWebPCoder` built-in coder). However it may contains some limitation, check https://github.com/SDWebImage/SDWebImage/issues/3558, you can still force to use this coder on those platforms by adding this coder.\n\n## Requirements\n\n+ iOS 9.0\n+ macOS 10.11\n+ tvOS 9.0\n+ watchOS 2.0\n+ Xcode 11.0\n\n## Installation\n\n#### CocoaPods\n\nSDWebImageWebPCoder is available through [CocoaPods](http://cocoapods.org). To install it, simply add the following line to your Podfile:\n\n```ruby\npod 'SDWebImageWebPCoder'\n```\n\n#### Carthage\n\nSDWebImageWebPCoder is available through [Carthage](https://github.com/Carthage/Carthage).\n\n```\ngithub \"SDWebImage/SDWebImageWebPCoder\"\n```\n\n#### Swift Package Manager (Xcode 11+)\n\nSDWebImageWebPCoder is available through [Swift Package Manager](https://swift.org/package-manager).\n\n```swift\nlet package = Package(\n    dependencies: [\n        .package(url: \"https://github.com/SDWebImage/SDWebImageWebPCoder.git\", from: \"0.3.0\")\n    ]\n)\n```\n\n## Usage\n\n### Add Coder\n\nBefore using SDWebImage to load WebP images, you need to register the WebP Coder to your coders manager. This step is recommended to be done after your App launch (like AppDelegate method).\n\n+ Objective-C\n\n```objective-c\n// Add coder\nSDImageWebPCoder *webPCoder = [SDImageWebPCoder sharedCoder];\n[[SDImageCodersManager sharedManager] addCoder:webPCoder];\n```\n\n+ Swift\n\n```swift\n// Add coder\nlet WebPCoder = SDImageWebPCoder.shared\nSDImageCodersManager.shared.addCoder(WebPCoder)\n```\n\n### Modify HTTP Accept Header\n\nSome of image server provider may try to detect the client supported format, by default, SDWebImage use `image/*,*/*;q=0.8` for [Accept](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept). You can modify it with the `image/webp` as well.\n\n+ Objective-C\n\n```objective-c\n[[SDWebImageDownloader sharedDownloader] setValue:@\"image/webp,image/*,*/*;q=0.8\" forHTTPHeaderField:@\"Accept\"];\n```\n\n+ Swift\n\n```swift\nSDWebImageDownloader.shared.setValue(\"image/webp,image/*,*/*;q=0.8\", forHTTPHeaderField:\"Accept\")\n```\n\n### Loading\n\n+ Objective-C\n\n```objective-c\n// WebP online image loading\nNSURL *webpURL;\nUIImageView *imageView;\n[imageView sd_setImageWithURL:webpURL];\n```\n\n+ Swift\n\n```swift\n// WebP online image loading\nlet webpURL: URL\nlet imageView: UIImageView\nimageView.sd_setImage(with: webpURL)\n```\n\n### Progressive Animation Loading (0.5.0+)\n\n+ Objective-C\n\n```objective-c\n// WebP progressive loading for animated image\nNSURL *webpURL;\nSDAnimatedImageView *imageView;\nimageView.shouldIncrementalLoad = YES;\n[imageView sd_setImageWithURL:webpURL placeholderImage:nil options:SDWebImageProgressiveLoad];\n```\n\n+ Swift\n\n```swift\n// WebP progressive loading for animated image\nlet webpURL: URL\nlet imageView: SDAnimatedImageView\nimageView.shouldIncrementalLoad = true\nimageView.sd_setImage(with: webpURL, placeholderImage: nil, options: [.progressiveLoad])\n```\n\n### Decoding\n\n+ Objective-C\n\n```objective-c\n// WebP image decoding\nNSData *webpData;\nUIImage *image = [[SDImageWebPCoder sharedCoder] decodedImageWithData:webpData options:nil];\n```\n\n+ Swift\n\n```swift\n// WebP image decoding\nlet webpData: Data\nlet image = SDImageWebPCoder.shared.decodedImage(with: data, options: nil)\n```\n\n### Thumbnail Decoding (0.4.0+)\n\n+ Objective-C\n\n```objective-c\n// WebP thumbnail image decoding\nNSData *webpData;\nCGSize thumbnailSize = CGSizeMake(300, 300);\nUIImage *thumbnailImage = [[SDImageWebPCoder sharedCoder] decodedImageWithData:webpData options:@{SDImageCoderDecodeThumbnailPixelSize : @(thumbnailSize)}];\n```\n\n+ Swift\n\n```swift\n// WebP thumbnail image decoding\nlet webpData: Data\nlet thumbnailSize = CGSize(width: 300, height: 300)\nlet image = SDImageWebPCoder.shared.decodedImage(with: data, options: [.decodeThumbnailPixelSize: thumbnailSize])\n```\n\n### Decoding with limit bytes (0.12.0+)\n\n+ Objective-C\n\n```objective-c\n// WebP thumbnail image decoding\nNSData *webpData;\nNSUInteger limitBytes = 1024 * 1024; // 1MB\nUIImage *image = [[SDImageWebPCoder sharedCoder] decodedImageWithData:webpData options:@{SDImageCoderDecodeScaleDownLimitBytes : @(limitBytes)}];\n// The image pixel buffer is guaranteed to less than 1MB in RAM (may scale down or full size), suitable for large image\n```\n\n+ Swift\n\n```swift\n// WebP thumbnail image decoding\nlet webpData: Data\nlet limitBytes = 1024 * 1024 // 1MB\nlet image = SDImageWebPCoder.shared.decodedImage(with: data, options: [.decodeScaleDownLimitBytes: limitBytes])\n// The image pixel buffer is guaranteed to less than 1MB in RAM (may scale down or full size), suitable for large image\n```\n\n### Encoding\n\n+ Objective-c\n\n```objective-c\n// WebP image encoding\nUIImage *image;\nNSData *webpData = [[SDImageWebPCoder sharedCoder] encodedDataWithImage:image format:SDImageFormatWebP options:nil];\n// Animated encoding\nNSArray\u003cSDImageFrames *\u003e *frames;\nNSData *awebpData = [[SDImageWebPCoder sharedCoder] encodedDataWithFrames:frames loopCount:0 format:SDImageFormatWebP options:nil];\n// Encode Quality\nNSData *lossyWebpData = [[SDImageWebPCoder sharedCoder] encodedDataWithImage:image format:SDImageFormatWebP options:@{SDImageCoderEncodeCompressionQuality : @(0.1)}]; // [0, 1] compression quality\nNSData *limitedWebpData = [[SDImageWebPCoder sharedCoder] encodedDataWithImage:image format:SDImageFormatWebP options:@{SDImageCoderEncodeMaxFileSize : @(1024 * 10)}]; // v0.6.0 feature, limit output file size \u003c= 10KB\n```\n\n+ Swift\n\n```swift\n// WebP image encoding\nlet image: UIImage\nlet webpData = SDImageWebPCoder.shared.encodedData(with: image, format: .webP, options: nil)\n// Animated encoding\nlet frames: [SDImageFrame]\nlet awebpData = SDImageWebPCoder.shared.encodedData(with: frames, loopCount: 0, format: .webP, options: nil)\n// Encode Quality\nlet lossyWebpData = SDImageWebPCoder.shared.encodedData(with: image, format: .webP, options: [.encodeCompressionQuality: 0.1]) // [0, 1] compression quality\nlet limitedWebpData = SDImageWebPCoder.shared.encodedData(with: image, format: .webP, options: [.encodeMaxFileSize: 1024 * 10]) // v0.6.0 feature, limit output file size \u003c= 10KB\n```\n\n### Thumbnail Encoding (0.6.1+)\n\n+ Objective-C\n\n```objective-c\n// WebP image thumbnail encoding\nUIImage *image;\nNSData *thumbnailWebpData = [[SDImageWebPCoder sharedCoder] encodedDataWithImage:image format:SDImageFormatWebP options:@{SDImageCoderEncodeMaxPixelSize : @(CGSizeMake(200, 200))}]; // v0.6.1 feature, encoding max pixel size\n```\n\n+ Swift\n\n```swift\n// WebP image thumbnail encoding\nlet image: UIImage\nlet thumbnailWebpData = SDImageWebPCoder.shared.encodedData(with: image, format: .webP, options: [.encodeMaxPixelSize: CGSize(width: 200, height: 200)]) // v0.6.1 feature, encoding max pixel size\n```\n\nSee more documentation in [SDWebImage Wiki - Coders](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#custom-coder-420)\n\n### Animated WebP Encoding (0.10+)\n\n+ Objective-c\n\n```objective-c\n// Animated encoding\nNSMutableArray\u003cSDImageFrames *\u003e *frames = [NSMutableArray array];\nfor (size_t i = 0; i \u003c images.count; i++) {\n    SDImageFrame *frame = [SDImageFrame frameWithImage:images[i] duration:0.1];\n    [frames appendObject:frame];\n}\nNSData *awebpData = [[SDImageWebPCoder sharedCoder] encodedDataWithFrames:frames loopCount:0 format:SDImageFormatWebP options:nil];\n```\n\n+ Swift\n\n```swift\n// Animated encoding\nvar frames: [SDImageFrame] = []\nfor i in 0..\u003cimages.count {\n    let frame = SDImageFrame(image: images[i], duration: 0.1)\n    frames.append(frame)\n}\nlet awebpData = SDImageWebPCoder.shared.encodedData(with: frames, loopCount: 0, format: .webP, options: nil)\n```\n\n### Advanced WebP codec options (0.8+)\n\nThe WebP codec [libwebp](https://developers.google.com/speed/webp/docs/api) we use, supports some advanced control options for encoding/decoding. You can pass them to libwebp by using the wrapper top level API:\n\n+ Objective-C\n\n```objective-c\nUIImage *image;\nSDImageCoderOptions *options = @{SDImageCoderEncodeWebPMethod: @(0), SDImageCoderEncodeWebPAlphaCompression: @(100)};\nNSData *data = [SDImageWebPCoder.sharedCoder encodedDataWithImage:image format:SDImageFormatWebP options:options];\n// Will translate into:\n// config-\u003emethod = 0;\n// config-\u003ealpha_quality = 100;\n```\n\n+ Swift\n\n```swift\nlet image: UIImage\nlet options = [.encodeWebPMethod: 0, .encodeWebPAlphaCompression: 100]\nlet data = SDImageWebPCoder.shared.encodedData(with: image, format: .webP, options: options)\n// Will translate into:\n// config-\u003emethod = 0;\n// config-\u003ealpha_quality = 100;\n```\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the root directory first. Then open `SDWebImageWebPCoder.xcworkspace`.\n\nThis is a demo to show how to use `WebP` and animated `WebP` images via `SDWebImageWebPCoderExample` target.\n\n## Screenshot\n\n\u003cimg src=\"https://raw.githubusercontent.com/SDWebImage/SDWebImageWebPCoder/master/Example/Screenshot/WebPDemo.png\" width=\"300\" /\u003e\n\nThese WebP images are from [WebP Gallery](https://developers.google.com/speed/webp/gallery1) and [GIF vs APNG vs WebP](http://littlesvr.ca/apng/gif_apng_webp.html)\n\n## Author\n\n[Bogdan Poplauschi](https://github.com/bpoplauschi)\n[DreamPiggy](https://github.com/dreampiggy)\n\n## License\n\nSDWebImageWebPCoder is available under the MIT license. See [the LICENSE file](https://github.com/SDWebImage/SDWebImageWebPCoder/blob/master/LICENSE) for more info.\n\n\n","funding_links":[],"categories":["iOS"],"sub_categories":["webp"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSDWebImage%2FSDWebImageWebPCoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSDWebImage%2FSDWebImageWebPCoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSDWebImage%2FSDWebImageWebPCoder/lists"}