Skip to content

Commit 6f14ff2

Browse files
committed
Update the Example and Readme about the new context option
1 parent 4f0a11c commit 6f14ff2

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

Example/SDWebImageSVGCoder/SDViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ - (void)viewDidLoad
6565
}];
6666
}
6767
}];
68-
[imageView3 sd_setImageWithURL:svgURL3 placeholderImage:nil options:SDWebImageRetryFailed context:@{SDWebImageContextSVGPrefersBitmap: @(YES), SDWebImageContextSVGImageSize: @(CGSizeMake(100, 100))} progress:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
68+
[imageView3 sd_setImageWithURL:svgURL3 placeholderImage:nil options:SDWebImageRetryFailed context:@{SDWebImageContextImageThumbnailPixelSize: @(CGSizeMake(100, 100))} progress:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
6969
if (image) {
7070
NSLog(@"SVG bitmap load success.");
7171
NSData *svgData = [image sd_imageDataAsFormat:SDImageFormatSVG];

README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ SDWebImageSVGCoder is available through [Swift Package Manager](https://swift.or
5959
```swift
6060
let package = Package(
6161
dependencies: [
62-
.package(url: "https://github.com/SDWebImage/SDWebImageSVGCoder.git", from: "1.0")
62+
.package(url: "https://github.com/SDWebImage/SDWebImageSVGCoder.git", from: "1.4")
6363
]
6464
)
6565
```
@@ -108,24 +108,26 @@ Note since UIImageView/NSImageView support this vector rendering, it means this
108108

109109
### Render SVG as bitmap image
110110

111-
In most cases, vector SVG is preferred. But however, sometimes you may want the bitmap form of SVG, used for image processing. You can use `.svgPrefersBitmap` to provide the bitmap format as well.
111+
In most cases, vector SVG is preferred. But however, sometimes you may want the bitmap form of SVG, used for image processing.
112112

113-
By default it use the SVG canvas size. You can also specify a desired size during image loading using `.svgImageSize` context option. And you can specify whether or not to keep aspect ratio during scale using `.svgImagePreserveAspectRatio` context option.
113+
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.
114+
115+
Note: Once you pass the pixel size, we will always generate the bitmap representation even on iOS/tvOS 11+. If you want the vector format, do not pass them, let `UIImageView` to dynamically stretch the SVG.
114116

115117
+ Objective-C
116118

117119
```objectivec
118120
UIImageView *imageView;
119-
CGSize SVGImageSize = CGSizeMake(500, 500);
120-
[imageView sd_setImageWithURL:url placeholderImage:nil options:0 context:@{SDWebImageContextSVGPrefersBitmap: @YES, SDWebImageContextSVGImageSize: @(SVGImageSize)];
121+
CGSize bitmapSize = CGSizeMake(500, 500);
122+
[imageView sd_setImageWithURL:url placeholderImage:nil options:0 context:@{SDWebImageContextThumbnailPixelSize: @(bitmapSize)];
121123
```
122124
123125
+ Swift
124126
125127
```swift
126128
let imageView: UIImageView
127-
let SVGImageSize = CGSize(width: 500, height: 500)
128-
imageView.sd_setImage(with: url, placeholderImage: nil, options: [], context: [.svgPrefersBitmap : true, .svgImageSize : SVGImageSize])
129+
let bitmapSize = CGSize(width: 500, height: 500)
130+
imageView.sd_setImage(with: url, placeholderImage: nil, options: [], context: [.imageThumbnailPixelSize : bitmapSize])
129131
```
130132

131133
## Export SVG data
@@ -137,15 +139,19 @@ Note: The bitmap form of SVG does not support SVG data export.
137139
+ Objective-C
138140

139141
```objectivec
140-
UIImage *image = imageView.image; // Image generated by this coder plugin
141-
NSData *imageData = [image sd_imageDataAsFormat:SDImageFormatSVG];
142+
UIImage *svgImage; // UIImage with vector image, or NSImage contains `NSSVGImageRep`
143+
if (svgImage.sd_isVector) { // This API available in SDWebImage 5.6.0
144+
NSData *svgData = [svgImage sd_imageDataAsFormat:SDImageFormatSVG];
145+
}
142146
```
143147

144148
+ Swift
145149

146150
```swift
147-
let image = imageView.image // Image generated by this coder plugin
148-
let imageData = image.sd_imageData(as: .SVG)
151+
let svgImage: UIImage // UIImage with vector image, or NSImage contains `NSSVGImageRep`
152+
if svgImage.sd_isVector { // This API available in SDWebImage 5.6.0
153+
let svgData = svgImage.sd_imageData(as: .SVG)
154+
}
149155
```
150156

151157
## Backward Deployment

0 commit comments

Comments
 (0)