{"id":28559051,"url":"https://github.com/sdwebimage/sdwebimagesvgcoder","last_synced_at":"2025-06-10T08:36:00.147Z","repository":{"id":44746542,"uuid":"150608047","full_name":"SDWebImage/SDWebImageSVGCoder","owner":"SDWebImage","description":"A SVG coder plugin for SDWebImage, using Apple's built-in framework","archived":false,"fork":false,"pushed_at":"2024-12-11T09:47:01.000Z","size":2911,"stargazers_count":122,"open_issues_count":8,"forks_count":37,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-06-04T03:35:00.985Z","etag":null,"topics":["ios","macos","sdwebimage","svg","tvos","watchos"],"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,"zenodo":null}},"created_at":"2018-09-27T15:23:34.000Z","updated_at":"2025-06-03T10:11:19.000Z","dependencies_parsed_at":"2024-01-29T10:09:34.938Z","dependency_job_id":"4903ca97-9ca5-404a-a3fb-351aecb846a5","html_url":"https://github.com/SDWebImage/SDWebImageSVGCoder","commit_stats":{"total_commits":80,"total_committers":6,"mean_commits":"13.333333333333334","dds":0.0625,"last_synced_commit":"6de587af4f5b775c18665b90b86bec0ba7a4ac4e"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDWebImage%2FSDWebImageSVGCoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDWebImage%2FSDWebImageSVGCoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDWebImage%2FSDWebImageSVGCoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDWebImage%2FSDWebImageSVGCoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SDWebImage","download_url":"https://codeload.github.com/SDWebImage/SDWebImageSVGCoder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDWebImage%2FSDWebImageSVGCoder/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259039550,"owners_count":22796854,"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":["ios","macos","sdwebimage","svg","tvos","watchos"],"created_at":"2025-06-10T08:35:58.270Z","updated_at":"2025-06-10T08:36:00.106Z","avatar_url":"https://github.com/SDWebImage.png","language":"Objective-C","readme":"# SDWebImageSVGCoder\n\n[![CI Status](https://img.shields.io/travis/SDWebImage/SDWebImageSVGCoder.svg?style=flat)](https://travis-ci.org/SDWebImage/SDWebImageSVGCoder)\n[![Version](https://img.shields.io/cocoapods/v/SDWebImageSVGCoder.svg?style=flat)](https://cocoapods.org/pods/SDWebImageSVGCoder)\n[![License](https://img.shields.io/cocoapods/l/SDWebImageSVGCoder.svg?style=flat)](https://cocoapods.org/pods/SDWebImageSVGCoder)\n[![Platform](https://img.shields.io/cocoapods/p/SDWebImageSVGCoder.svg?style=flat)](https://cocoapods.org/pods/SDWebImageSVGCoder)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/SDWebImage/SDWebImageSVGCoder)\n\n\n## Background\n\nCurrently SDWebImage org provide 3 kinds of SVG Coder Plugin support, here is comparison:\n\n| Plugin Name| Vector Image | Bitmap Image | Platform | Compatibility | Dependency |\n|---|---|---|---|---|---|\n| [SVGNativeCoder](https://github.com/SDWebImage/SDWebImageSVGNativeCoder) | NO | YES | iOS 9+ | Best and W3C standard | adobe/svg-native-viewer |\n| [SVGCoder](https://github.com/SDWebImage/SDWebImageSVGCoder) | YES | YES | iOS 13+ | OK but buggy on some SVG | Apple CoreSVG(Private) |\n| [SVGKitPlugin](https://github.com/SDWebImage/SDWebImageSVGKitPlugin) | YES | NO | iOS 9+ | Worst, no longer maintain | SVGKit/SVGKit    \n\n## What's for\nSDWebImageSVGCoder is a SVG coder plugin for [SDWebImage](https://github.com/rs/SDWebImage/) framework, which provide the image loading support for [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics).\n\nThe SVG rendering is done using Apple's framework CoreSVG.framework (introduced in iOS 13/macOS 10.15).\n\n## Note for SVGKit user\n\nPreviously before 1.0.0 version, this SVG Coder is powered by third party library [SVGKit](https://github.com/SVGKit/SVGKit). Which support iOS 8+(macOS 10.10+) as well.\n\nHowever, due to the lack support of that third party library, which contains massive issues without community's help, no clarity of version release, makes a pain for us to maintain. So, We decide to deprecate SVGKit support and move it into another repo: [SDWebImageSVGKitPlugin](https://github.com/SDWebImage/SDWebImageSVGKitPlugin).\n\nUser who use SVGKit or have to support iOS 8+(macOS 10.10+) can still use that SDWebImageSVGKitPlugin instead. You can also mix these two SVG coders at the same time. But since Apple already provide a built-in framework support, we prefer to use that instead, which can reduce complicated dependency, code size, and get polished from Apple's system upgrade.\n\n## Note for CoreSVG framework\n\nSo far (Xcode 11.4 \u0026\u0026 iOS 13.4), the CoreSVG.framework is still in private framework. I've already send the feedback radar to ask for the public for this framework. If you want, please help us to fire radars and request to Apple as well: https://feedbackassistant.apple.com/\n\nThe CoreSVG.framework API is stable and match the same concept as CoreGraphics's PDF API, so it's no reason to keep private. And we've already submitted Apps which use the CoreSVG to render the vector images on App Store.\n\nAll the SPI access here we use the runtime access and early check, even if future OS upgrade break the function, this framework will not crash your App and just load failed. I'll keep update to the latest changes for each firmware update.\n\nIf you still worry about the SPI usage, you can use [SDWebImageSVGKitPlugin](https://github.com/SDWebImage/SDWebImageSVGKitPlugin). But we may not response to any parser or rendering issue related to [SVGKit](https://github.com/SVGKit/SVGKit), because it's already no longer maintained.\n\nThere is also another solution: [SVG-Native](https://w3c.github.io/svgwg/specs/svg-native/index.html), a new W3C standard from Adobe, which is a subset of SVG/1.1. Both Apple/Google/Microsoft already join the agreement for this standard, you can try to write your own coder using code from [SVG-native-viewer](https://github.com/adobe/svg-native-viewer/blob/master/svgnative/example/testCocoaCG/SVGNSView.mm) and adopt SVG-native for vector images.\n\n\u003e Warning: Some user report that Apple's CoreSVG has compatible issue for some SVGs (like using non-system Font, gradient), from v1.7.0 we protect some cases, but other exceptions are un-catchable. For these crashes, either use `Render SVG as bitmap image` (see below) or edit your SVG source file to make Apple's CoeSVG compatible.\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\nYou can modify the code or use some other SVG files to check the compatibility.\n\n## Requirements\n\n+ iOS 13+\n+ tvOS 13+\n+ macOS 10.15+\n+ watchOS 6+\n\n## Installation\n\n#### CocoaPods\n\nSDWebImageSVGCoder is available through [CocoaPods](https://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'SDWebImageSVGCoder'\n```\n\n#### Carthage\n\nSDWebImageSVGCoder is available through [Carthage](https://github.com/Carthage/Carthage).\n\n```\ngithub \"SDWebImage/SDWebImageSVGCoder\"\n```\n\n#### Swift Package Manager\n\nSDWebImageSVGCoder 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/SDWebImageSVGCoder.git\", from: \"1.4.0\")\n    ]\n)\n```\n\n## Usage\n\n### Render SVG as vector image\n\nTo use SVG coder, you should firstly add the `SDImageSVGCoder` to the coders manager. Then you can call the View Category method to start load SVG images. See [Wiki - Coder Usage](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#coder-usage) here for these steps.\n\nNote SVG is a [vector image](https://en.wikipedia.org/wiki/Vector_graphics) format, and UIImageView/NSImageView support rendering vector image as well. Which means you can change the size without losing any details.\n\n+ Objective-C\n\n```objectivec\n// register coder, on AppDelegate\nSDImageSVGCoder *SVGCoder = [SDImageSVGCoder sharedCoder];\n[[SDImageCodersManager sharedManager] addCoder:SVGCoder];\n// load SVG url\nUIImageView *imageView;\n[imageView sd_setImageWithURL:url]\n// Changing size\nCGRect rect = imageView.frame;\nrect.size.width = 200;\nrect.size.height = 200;\nimageView.frame = rect;\n```\n\n+ Swift\n\n```swift\n// register coder, on AppDelegate\nlet SVGCoder = SDImageSVGCoder.shared\nSDImageCodersManager.shared.addCoder(SVGCoder)\n// load SVG url\nlet imageView: UIImageView\nimageView.sd_setImage(with: url)\n// Changing size\nvar rect = imageView.frame\nrect.size.width = 200\nrect.size.height = 200\nimageView.frame = rect\n```\n\nNote since UIImageView/NSImageView support this vector rendering, it means this coder plugin can be compatible for [SwiftUI](https://developer.apple.com/xcode/swiftui/). Check [SDWebImageSwiftUI](https://github.com/SDWebImage/SDWebImageSwiftUI/issues/50) for usage.\n\nNote: for watchOS, which does not support UIKit, so you can not use vector image format. (including both SVG and PDF)\n\n### Render SVG as bitmap image\n\nIn most cases, vector SVG is preferred. But however, sometimes you may want the bitmap form of SVG, used for image processing or watchOS.\n\nBy default it use the SVG viewBox size. You can also specify a desired size during image loading using `.imageThumbnailPixelSize` context option. And you can specify whether or not to keep aspect ratio during scale using `.imagePreserveAspectRatio` context option.\n\nNote: When using `imageThumbnailPixelSize`, pass 0 for width or height will remove the limit of this length. For example, given a SVG image which original size is `(40,50)`:\n\n| preserve aspect ratio | width | height | effect |\n| --- | --- | --- | --- |\n| true | 50 | 50 | (40,50) |\n| true | 0 | 100 | (80,100) |\n| true | 20 | 0 | (20,25) |\n| true | 0 | 0 | (40,50) |\n| false | 50 | 50 | (50,50) |\n| false | 0 | 100 | (40,100) |\n| false | 20 | 0 | (20,50) |\n| false | 0 | 0 | (40,50) |\n\nNote: Once you pass the `imageThumbnailPixelSize`, we will always generate the bitmap representation. If you do want the vector format, do not pass them, let `UIImageView` to dynamically stretch the SVG.\n\n+ Objective-C\n\n```objectivec\nUIImageView *imageView;\nCGSize bitmapSize = CGSizeMake(500, 500);\n[imageView sd_setImageWithURL:url placeholderImage:nil options:0 context:@{SDWebImageContextThumbnailPixelSize: @(bitmapSize)];\n```\n\n+ Swift\n\n```swift\nlet imageView: UIImageView\nlet bitmapSize = CGSize(width: 500, height: 500)\nimageView.sd_setImage(with: url, placeholderImage: nil, options: [], context: [.imageThumbnailPixelSize : bitmapSize])\n```\n\n## Export SVG data\n\n`SDWebImageSVGCoder` provide an easy way to export the SVG image generated by this coder plugin, to the original SVG data.\n\nNote: The bitmap form of SVG does not support SVG data export.\n\n+ Objective-C\n\n```objectivec\nUIImage *svgImage; // UIImage with vector image, or NSImage contains `NSSVGImageRep`\nif (svgImage.sd_isVector) { // This API available in SDWebImage 5.6.0\n    NSData *svgData = [svgImage sd_imageDataAsFormat:SDImageFormatSVG];\n}\n```\n\n+ Swift\n\n```swift\nlet svgImage: UIImage // UIImage with vector image, or NSImage contains `NSSVGImageRep`\nif svgImage.sd_isVector { // This API available in SDWebImage 5.6.0\n    let svgData = svgImage.sd_imageData(as: .SVG)\n}\n```\n\n## Compatibility for CoreSVG framework\n\n#### The CSS `opacity` can not been applied when `fill` color exists\n\n+ Example\n\n```html\n\u003cpath d=\"M399.8,68.2c77.3,3.1,160.6,32.1\" opacity=\"0.15\" fill=\"rgb(29,36,60)\" /\u003e\n```\n\n+ Behavior\n\nApp Crash.\n\n+ Workaround: Use CSS `rgba` to set the opacity instead.\n\n```html\n\u003cpath d=\"M399.8,68.2c77.3,3.1,160.6,32.1\" fill=\"rgba(29,36,60,0.15)\" /\u003e\n```\n\n## Backward Deployment\n\nThis framework supports backward deployment on iOS 12-/macOS 10.14-. And you can combine both `SDWebImageSVGCoder` for higher firmware version, use `SDWebImageSVGKitPlugin` for lower firmware version.\n\nFor CocoaPods user, you can skip the platform version validation in Podfile with:\n\n```ruby\nplatform :ios, '13.0' # This does not effect your App Target's deployment target version, just a hint for CocoaPods\n```\n\nPay attention, you should always use the runtime version check to ensure those symbols are available, you should mark all the classes use public API with `API_AVAILABLE` annotation as well. See below:\n\n```objective-c\nif (@available(iOS 13, *)) {\n    [SDImageCodersManager.sharedCoder addCoder:SDImageSVGCoder.sharedCoder];\n} else {\n    [SDImageCodersManager.sharedCoder addCoder:SDImageSVGKCoder.sharedCoder];\n}\n```\n\n## Screenshot\n\n\u003cimg src=\"https://raw.githubusercontent.com/SDWebImage/SDWebImageSVGCoder/master/Example/Screenshot/SVGDemo.png\" width=\"300\" /\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/SDWebImage/SDWebImageSVGCoder/master/Example/Screenshot/SVGDemo-macOS.png\" width=\"600\" /\u003e\n\nThese SVG images are from [wikimedia](https://commons.wikimedia.org/wiki/Main_Page), you can try the demo with your own SVG image as well.\n\n## Author\n\nDreamPiggy\n\n## License\n\nSDWebImageSVGCoder is available under the MIT license. See the LICENSE file for more info.\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsdwebimage%2Fsdwebimagesvgcoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsdwebimage%2Fsdwebimagesvgcoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsdwebimage%2Fsdwebimagesvgcoder/lists"}