{"id":1436,"url":"https://github.com/ibireme/YYImage","last_synced_at":"2025-08-02T04:31:24.261Z","repository":{"id":1785636,"uuid":"44871645","full_name":"ibireme/YYImage","owner":"ibireme","description":"Image framework for iOS to display/encode/decode animated WebP, APNG, GIF, and more.","archived":false,"fork":false,"pushed_at":"2024-06-27T04:53:47.000Z","size":30513,"stargazers_count":1777,"open_issues_count":105,"forks_count":489,"subscribers_count":54,"default_branch":"master","last_synced_at":"2025-08-01T22:49:18.176Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ibireme.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":"2015-10-24T15:17:24.000Z","updated_at":"2025-07-28T13:49:57.000Z","dependencies_parsed_at":"2024-11-26T15:03:46.197Z","dependency_job_id":null,"html_url":"https://github.com/ibireme/YYImage","commit_stats":{"total_commits":80,"total_committers":11,"mean_commits":"7.2727272727272725","dds":"0.13749999999999996","last_synced_commit":"42ba209608cb332887a33ebcae1bde50c52b151d"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/ibireme/YYImage","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibireme%2FYYImage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibireme%2FYYImage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibireme%2FYYImage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibireme%2FYYImage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ibireme","download_url":"https://codeload.github.com/ibireme/YYImage/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibireme%2FYYImage/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268322032,"owners_count":24231811,"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","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-01-05T20:15:46.429Z","updated_at":"2025-08-02T04:31:23.016Z","avatar_url":"https://github.com/ibireme.png","language":"Objective-C","funding_links":[],"categories":["Media","Objective-C","iOS"],"sub_categories":["GIF","Other free courses","YYKit"],"readme":"YYImage\n==============\n[![License MIT](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/ibireme/YYImage/master/LICENSE)\u0026nbsp;\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\u0026nbsp;\n[![CocoaPods](http://img.shields.io/cocoapods/v/YYImage.svg?style=flat)](http://cocoapods.org/pods/YYImage)\u0026nbsp;\n[![CocoaPods](http://img.shields.io/cocoapods/p/YYImage.svg?style=flat)](http://cocoadocs.org/docsets/YYImage)\u0026nbsp;\n[![Support](https://img.shields.io/badge/support-iOS%206%2B%20-blue.svg?style=flat)](https://www.apple.com/nl/ios/)\u0026nbsp;\n[![Build Status](https://travis-ci.org/ibireme/YYImage.svg?branch=master)](https://travis-ci.org/ibireme/YYImage)\n\nImage framework for iOS to display/encode/decode animated WebP, APNG, GIF, and more.\u003cbr/\u003e\n(It's a component of [YYKit](https://github.com/ibireme/YYKit))\n\n![niconiconi~](https://raw.github.com/ibireme/YYImage/master/Demo/YYImageDemo/niconiconi@2x.gif\n)\n\nFeatures\n==============\n- Display/encode/decode animated image with these types:\u003cbr/\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;WebP, APNG, GIF.\n- Display/encode/decode still image with these types:\u003cbr/\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;WebP, PNG, GIF, JPEG, JP2, TIFF, BMP, ICO, ICNS.\n- Baseline/progressive/interlaced image decode with these types:\u003cbr/\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;PNG, GIF, JPEG, BMP.\n- Display frame based image animation and sprite sheet animation.\n- Dynamic memory buffer for lower memory usage.\n- Fully compatible with UIImage and UIImageView class.\n- Extendable protocol for custom image animation.\n- Fully documented.\n\nUsage\n==============\n\n### Display animated image\n```objc\n// File: ani@3x.gif\nUIImage *image = [YYImage imageNamed:@\"ani.gif\"];\nUIImageView *imageView = [[YYAnimatedImageView alloc] initWithImage:image];\n[self.view addSubview:imageView];\n```\n\n### Display frame animation\n```objc\n// Files: frame1.png, frame2.png, frame3.png\nNSArray *paths = @[@\"/ani/frame1.png\", @\"/ani/frame2.png\", @\"/ani/frame3.png\"];\nNSArray *times = @[@0.1, @0.2, @0.1];\nUIImage *image = [YYFrameImage alloc] initWithImagePaths:paths frameDurations:times repeats:YES];\nUIImageView *imageView = [YYAnimatedImageView alloc] initWithImage:image];\n[self.view addSubview:imageView];\n```\n\n### Display sprite sheet animation\n```objc\n// 8 * 12 sprites in a single sheet image\nUIImage *spriteSheet = [UIImage imageNamed:@\"sprite-sheet\"];\nNSMutableArray *contentRects = [NSMutableArray new];\nNSMutableArray *durations = [NSMutableArray new];\nfor (int j = 0; j \u003c 12; j++) {\n   for (int i = 0; i \u003c 8; i++) {\n       CGRect rect;\n       rect.size = CGSizeMake(img.size.width / 8, img.size.height / 12);\n       rect.origin.x = img.size.width / 8 * i;\n       rect.origin.y = img.size.height / 12 * j;\n       [contentRects addObject:[NSValue valueWithCGRect:rect]];\n       [durations addObject:@(1 / 60.0)];\n   }\n}\nYYSpriteSheetImage *sprite;\nsprite = [[YYSpriteSheetImage alloc] initWithSpriteSheetImage:img\n                                                contentRects:contentRects\n                                              frameDurations:durations\n                                                   loopCount:0];\nYYAnimatedImageView *imageView = [YYAnimatedImageView new];\nimageView.size = CGSizeMake(img.size.width / 8, img.size.height / 12);\nimageView.image = sprite;\n[self.view addSubview:imageView];\n```\n\n### Animation control\n```objc\nYYAnimatedImageView *imageView = ...;\n// pause:\n[imageView stopAnimating];\n// play:\n[imageView startAnimating];\n// set frame index:\nimageView.currentAnimatedImageIndex = 12;\n// get current status\nimage.currentIsPlayingAnimation;\n```\n\n### Image decoder\n```objc\n// Decode single frame:\nNSData *data = [NSData dataWithContentsOfFile:@\"/tmp/image.webp\"];\nYYImageDecoder *decoder = [YYImageDecoder decoderWithData:data scale:2.0];\nUIImage image = [decoder frameAtIndex:0 decodeForDisplay:YES].image;\n\t\n// Progressive:\nNSMutableData *data = [NSMutableData new];\nYYImageDecoder *decoder = [[YYImageDecoder alloc] initWithScale:2.0];\nwhile(newDataArrived) {\n   [data appendData:newData];\n   [decoder updateData:data final:NO];\n   if (decoder.frameCount \u003e 0) {\n       UIImage image = [decoder frameAtIndex:0 decodeForDisplay:YES].image;\n       // progressive display...\n   }\n}\n[decoder updateData:data final:YES];\nUIImage image = [decoder frameAtIndex:0 decodeForDisplay:YES].image;\n// final display...\n```\n\n### Image encoder\n```objc\n// Encode still image:\nYYImageEncoder *jpegEncoder = [[YYImageEncoder alloc] initWithType:YYImageTypeJPEG];\njpegEncoder.quality = 0.9;\n[jpegEncoder addImage:image duration:0];\nNSData jpegData = [jpegEncoder encode];\n \n// Encode animated image:\nYYImageEncoder *webpEncoder = [[YYImageEncoder alloc] initWithType:YYImageTypeWebP];\nwebpEncoder.loopCount = 5;\n[webpEncoder addImage:image0 duration:0.1];\n[webpEncoder addImage:image1 duration:0.15];\n[webpEncoder addImage:image2 duration:0.2];\nNSData webpData = [webpEncoder encode];\n```\n\n### Image type detection\n```objc\n// Get image type from image data\nYYImageType type = YYImageDetectType(data); \nif (type == YYImageTypePNG) ...\n```\n\t\nInstallation\n==============\n\n### CocoaPods\n\n1. Update cocoapods to the latest version.\n2. Add `pod 'YYImage'` to your Podfile.\n3. Run `pod install` or `pod update`.\n4. Import \\\u003cYYImage/YYImage.h\\\u003e.\n5. Notice: it doesn't include WebP subspec by default, if you want to support WebP format, you may add `pod 'YYImage/WebP'` to your Podfile.\n\n### Carthage\n\n1. Add `github \"ibireme/YYImage\"` to your Cartfile.\n2. Run `carthage update --platform ios` and add the framework to your project.\n3. Import \\\u003cYYImage/YYImage.h\\\u003e.\n4. Notice: carthage framework doesn't include WebP component, if you want to support WebP format, use CocoaPods or install manually.\n\n### Manually\n\n1. Download all the files in the YYImage subdirectory.\n2. Add the source files to your Xcode project.\n3. Link with required frameworks:\n\t* UIKit\n\t* CoreFoundation\n\t* QuartzCore\n\t* AssetsLibrary\n\t* ImageIO\n\t* Accelerate\n\t* MobileCoreServices\n\t* libz\n4. Import `YYImage.h`.\n5. Notice: if you want to support WebP format, you may add `Vendor/WebP.framework`(static library) to your Xcode project.\n\nFAQ\n==============\n_Q: Why I can't display WebP image?_\n\nA: Make sure you added the `WebP.framework` in your project. You may call `YYImageWebPAvailable()` to check whether the WebP subspec is installed correctly.\n\n_Q: Why I can't play APNG animation?_\n\nA: You should disable the `Compress PNG Files` and `Remove Text Metadata From PNG Files` in your project's build settings. Or you can rename your APNG file's extension name with `apng`.\n\nDocumentation\n==============\nFull API documentation is available on [CocoaDocs](http://cocoadocs.org/docsets/YYImage/).\u003cbr/\u003e\nYou can also install documentation locally using [appledoc](https://github.com/tomaz/appledoc).\n\n\n\nRequirements\n==============\nThis library requires `iOS 6.0+` and `Xcode 8.0+`.\n\n\nLicense\n==============\nYYImage is provided under the MIT license. See LICENSE file for details.\n\n\n\u003cbr/\u003e\u003cbr/\u003e\n---\n中文介绍\n==============\nYYImage: 功能强大的 iOS 图像框架。\u003cbr/\u003e\n(该项目是 [YYKit](https://github.com/ibireme/YYKit) 组件之一)\n\n![niconiconi~](https://raw.github.com/ibireme/YYImage/master/Demo/YYImageDemo/niconiconi@2x.gif\n)\n\n特性\n==============\n- 支持以下类型动画图像的播放/编码/解码:\u003cbr/\u003e\n  \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;WebP, APNG, GIF。\n- 支持以下类型静态图像的显示/编码/解码:\u003cbr\u003e\n  \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;WebP, PNG, GIF, JPEG, JP2, TIFF, BMP, ICO, ICNS。\n- 支持以下类型图片的渐进式/逐行扫描/隔行扫描解码:\u003cbr/\u003e\n  \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;PNG, GIF, JPEG, BMP。\n- 支持多张图片构成的帧动画播放，支持单张图片的 sprite sheet 动画。\n- 高效的动态内存缓存管理，以保证高性能低内存的动画播放。\n- 完全兼容 UIImage 和 UIImageView，使用方便。\n- 保留可扩展的接口，以支持自定义动画。\n- 每个类和方法都有完善的文档注释。\n\n\n用法\n==============\n\n### 显示动画类型的图片\n```objc\n// 文件: ani@3x.gif\nUIImage *image = [YYImage imageNamed:@\"ani.gif\"];\nUIImageView *imageView = [[YYAnimatedImageView alloc] initWithImage:image];\n[self.view addSubview:imageView];\n```\n\n### 播放帧动画\n```objc\n// 文件: frame1.png, frame2.png, frame3.png\nNSArray *paths = @[@\"/ani/frame1.png\", @\"/ani/frame2.png\", @\"/ani/frame3.png\"];\nNSArray *times = @[@0.1, @0.2, @0.1];\nUIImage *image = [YYFrameImage alloc] initWithImagePaths:paths frameDurations:times repeats:YES];\nUIImageView *imageView = [YYAnimatedImageView alloc] initWithImage:image];\n[self.view addSubview:imageView];\n```\n\n### 播放 sprite sheet 动画\n```objc\n// 8 * 12 sprites in a single sheet image\nUIImage *spriteSheet = [UIImage imageNamed:@\"sprite-sheet\"];\nNSMutableArray *contentRects = [NSMutableArray new];\nNSMutableArray *durations = [NSMutableArray new];\nfor (int j = 0; j \u003c 12; j++) {\n   for (int i = 0; i \u003c 8; i++) {\n       CGRect rect;\n       rect.size = CGSizeMake(img.size.width / 8, img.size.height / 12);\n       rect.origin.x = img.size.width / 8 * i;\n       rect.origin.y = img.size.height / 12 * j;\n       [contentRects addObject:[NSValue valueWithCGRect:rect]];\n       [durations addObject:@(1 / 60.0)];\n   }\n}\nYYSpriteSheetImage *sprite;\nsprite = [[YYSpriteSheetImage alloc] initWithSpriteSheetImage:img\n                                                contentRects:contentRects\n                                              frameDurations:durations\n                                                   loopCount:0];\nYYAnimatedImageView *imageView = [YYAnimatedImageView new];\nimageView.size = CGSizeMake(img.size.width / 8, img.size.height / 12);\nimageView.image = sprite;\n[self.view addSubview:imageView];\n```\n\n### 动画播放控制\n```objc\nYYAnimatedImageView *imageView = ...;\n// 暂停:\n[imageView stopAnimating];\n// 播放:\n[imageView startAnimating];\n// 设置播放进度:\nimageView.currentAnimatedImageIndex = 12;\n// 获取播放状态:\nimage.currentIsPlayingAnimation;\n//上面两个属性都支持 KVO。\n```\n\n### 图片解码\n```objc\n// 解码单帧图片:\nNSData *data = [NSData dataWithContentsOfFile:@\"/tmp/image.webp\"];\nYYImageDecoder *decoder = [YYImageDecoder decoderWithData:data scale:2.0];\nUIImage image = [decoder frameAtIndex:0 decodeForDisplay:YES].image;\n\t\n// 渐进式图片解码 (可用于图片下载显示):\nNSMutableData *data = [NSMutableData new];\nYYImageDecoder *decoder = [[YYImageDecoder alloc] initWithScale:2.0];\nwhile(newDataArrived) {\n   [data appendData:newData];\n   [decoder updateData:data final:NO];\n   if (decoder.frameCount \u003e 0) {\n       UIImage image = [decoder frameAtIndex:0 decodeForDisplay:YES].image;\n       // progressive display...\n   }\n}\n[decoder updateData:data final:YES];\nUIImage image = [decoder frameAtIndex:0 decodeForDisplay:YES].image;\n// final display...\n```\n\n### 图片编码\n```objc\n// 编码静态图 (支持各种常见图片格式):\nYYImageEncoder *jpegEncoder = [[YYImageEncoder alloc] initWithType:YYImageTypeJPEG];\njpegEncoder.quality = 0.9;\n[jpegEncoder addImage:image duration:0];\nNSData jpegData = [jpegEncoder encode];\n \n// 编码动态图 (支持 GIF/APNG/WebP):\nYYImageEncoder *webpEncoder = [[YYImageEncoder alloc] initWithType:YYImageTypeWebP];\nwebpEncoder.loopCount = 5;\n[webpEncoder addImage:image0 duration:0.1];\n[webpEncoder addImage:image1 duration:0.15];\n[webpEncoder addImage:image2 duration:0.2];\nNSData webpData = [webpEncoder encode];\n```\n\t\n### 图片类型探测\n```objc\n// 获取图片类型\nYYImageType type = YYImageDetectType(data); \nif (type == YYImageTypePNG) ...\n```\t\n\n安装\n==============\n\n### CocoaPods\n\n1. 将 cocoapods 更新至最新版本.\n2. 在 Podfile 中添加 `pod 'YYImage'`。\n3. 执行 `pod install` 或 `pod update`。\n4. 导入 \\\u003cYYImage/YYImage.h\\\u003e。\n5. 注意：pod 配置并没有包含 WebP 组件, 如果你需要支持 WebP，可以在 Podfile 中添加 `pod 'YYImage/WebP'`。\n\n### Carthage\n\n1. 在 Cartfile 中添加 `github \"ibireme/YYImage\"`。\n2. 执行 `carthage update --platform ios` 并将生成的 framework 添加到你的工程。\n3. 导入 \\\u003cYYImage/YYImage.h\\\u003e。\n4. 注意：carthage framework 并没有包含 WebP 组件。如果你需要支持 WebP，可以用 CocoaPods 安装，或者手动安装。\n\n### 手动安装\n\n1. 下载 YYImage 文件夹内的所有内容。\n2. 将 YYImage 内的源文件添加(拖放)到你的工程。\n3. 链接以下 frameworks:\n\t* UIKit\n\t* CoreFoundation\n\t* QuartzCore\n\t* AssetsLibrary\n\t* ImageIO\n\t* Accelerate\n\t* MobileCoreServices\n\t* libz\n4. 导入 `YYImage.h`。\n5. 注意：如果你需要支持 WebP，可以将 `Vendor/WebP.framework`(静态库) 加入你的工程。\n\n常见问题\n==============\n_Q: 为什么我不能显示 WebP 图片？_\n\nA: 确保 `WebP.framework` 已经被添加到你的工程内了。你可以调用 `YYImageWebPAvailable()` 来检查一下 WebP 组件是否被正确安装。\n\n_Q: 为什么我不能播放 APNG 动画？_\n\nA: 你应该禁用 Build Settings 中的 `Compress PNG Files` 和 `Remove Text Metadata From PNG Files`. 或者你也可以把 APNG 文件的扩展名改为`apng`.\n\n文档\n==============\n你可以在 [CocoaDocs](http://cocoadocs.org/docsets/YYImage/) 查看在线 API 文档，也可以用 [appledoc](https://github.com/tomaz/appledoc) 本地生成文档。\n\n\n系统要求\n==============\n该项目最低支持 `iOS 6.0` 和 `Xcode 8.0`。\n\n\n许可证\n==============\nYYImage 使用 MIT 许可证，详情见 LICENSE 文件。\n\n\n相关链接\n==============\n[移动端图片格式调研](https://blog.ibireme.com/2015/11/02/mobile_image_benchmark/)\u003cbr/\u003e\n\n[iOS 处理图片的一些小 Tip](https://blog.ibireme.com/2015/11/02/ios_image_tips/)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibireme%2FYYImage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fibireme%2FYYImage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibireme%2FYYImage/lists"}