Skip to content

Commit

Permalink
Update the README and screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
dreampiggy committed Aug 3, 2022
1 parent 7ab7bf2 commit b2dcd46
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 5 deletions.
Binary file added Example/Screenshot/SVGDemo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 92 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,113 @@
[![License](https://img.shields.io/cocoapods/l/SDWebImageSVGNativeCoder.svg?style=flat)](https://cocoapods.org/pods/SDWebImageSVGNativeCoder)
[![Platform](https://img.shields.io/cocoapods/p/SDWebImageSVGNativeCoder.svg?style=flat)](https://cocoapods.org/pods/SDWebImageSVGNativeCoder)

## Example
## Background

To run the example project, clone the repo, and run `pod install` from the Example directory first.
Currently SDWebImage org provide 3 kinds of SVG Coder Plugin support, here is comparison:

| Plugin Name| Vector Image | Bitmap Image | Platform | Compatibility | Dependency |
|---|---|---|---|---|---|
| SVGNativeCoder | NO | YES | iOS 9+ | Best and W3C standard | adobe/svg-native-viewer |
| SVGCoder | YES | YES | iOS 13+ | OK but buggy on some SVG | Apple CoreSVG(Private) |
| SVGKitPlugin | YES | NO | iOS 9+ | Worst, no longer maintain | SVGKit/SVGKit

For now, I recommand to use this SVGNativeCoder for most cases, until there are any other native support on Apple platforms.

## Requirements

+ iOS 9+
+ tvOS 9+
+ macOS 10.11+
+ watchOS 2+

## Installation

#### CocoaPods

SDWebImageSVGNativeCoder is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:

```ruby
pod 'SDWebImageSVGNativeCoder'
```

#### Carthage

SDWebImageSVGNativeCoder is available through [Carthage](https://github.com/Carthage/Carthage).

```
github "SDWebImage/SDWebImageSVGNativeCoder"
```

#### Swift Package Manager

SDWebImageSVGNativeCoder is available through [Swift Package Manager](https://swift.org/package-manager).

```swift
let package = Package(
dependencies: [
.package(url: "https://github.com/SDWebImage/SDWebImageSVGNativeCoder.git", from: "1.4")
]
)
```

## Usage

### Register Coder Plugin

To use SVG coder, you should firstly add the `SDImageSVGNativeCoder` 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.

+ Objective-C

```objectivec
// register coder, on AppDelegate
SDImageSVGNativeCoder *SVGCoder = [SDImageSVGNativeCoder sharedCoder];
[[SDImageCodersManager sharedManager] addCoder:SVGCoder];
```
+ Swift
```swift
// register coder, on AppDelegate
let SVGCoder = SDImageSVGNativeCoder.shared
SDImageCodersManager.shared.addCoder(SVGCoder)
```


### Render SVG as bitmap image

This coder plugin only support bitmap SVG image, which means once you load an image, even you change the image view size, the image size will not dynamic change and has to stretch up and may be blur. So you'd better provide the suitable large enough image size (like your image view size).

By 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.

+ Objective-C

```objectivec
UIImageView *imageView;
CGSize bitmapSize = CGSizeMake(500, 500);
[imageView sd_setImageWithURL:url placeholderImage:nil options:0 context:@{SDWebImageContextThumbnailPixelSize: @(bitmapSize)];
```
+ Swift
```swift
let imageView: UIImageView
let bitmapSize = CGSize(width: 500, height: 500)
imageView.sd_setImage(with: url, placeholderImage: nil, options: [], context: [.imageThumbnailPixelSize : bitmapSize])
```

## Example

To run the example project, clone the repo, and run `pod install` from the Example directory first.

## Screenshot

<img src="https://raw.githubusercontent.com/SDWebImage/SDWebImageSVGNativeCoder/main/Example/Screenshot/SVGDemo.png" width="300" />

## Author

dreampiggy, lizhuoli1126@126.com
DreamPiggy

## License

SDWebImageSVGNativeCoder is available under the MIT license. See the LICENSE file for more info.
SDWebImageSVGNativeCoder is available under the MIT license. See the LICENSE file for more info.
2 changes: 1 addition & 1 deletion SDWebImageSVGNativeCoder.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ This SDWebImage coder plugin, use adobe svg-native-viewer library to provide SVG
}

s.dependency 'SDWebImage', '~> 5.10'
s.dependency 'svgnative'
s.dependency 'svgnative', '>= 0.1.0-beta'
end

0 comments on commit b2dcd46

Please sign in to comment.