Skip to content

Commit 040ab76

Browse files
committed
Update the readme about the replaced API and behavior
1 parent 4c0b146 commit 040ab76

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ SDWebImagePDFCoder is available through [Swift Package Manager](https://swift.or
4949
```swift
5050
let package = Package(
5151
dependencies: [
52-
.package(url: "https://github.com/SDWebImage/SDWebImagePDFCoder.git", from: "0.4")
52+
.package(url: "https://github.com/SDWebImage/SDWebImagePDFCoder.git", from: "0.6")
5353
]
5454
)
5555
```
@@ -86,18 +86,18 @@ imageView.sd_setImage(with: url)
8686

8787
For firmware which is below iOS/tvOS 11+, `UIImage` && `UIImageView` does not support vector image rendering. Even you can add PDF image in Xcode Asset Catalog, it was encoded to bitmap PNG format when compiled but not support runtime scale.
8888

89-
For `UIImageView`, we will only parse PDF with a fixed image size (from the PDF cropBox information). But we also support you to specify a desired size during image loading using `.pdfImageSize` context option. And you can specify whether or not to keep aspect ratio during scale using `.pdfImagePreserveAspectRatio` context option.
89+
For `UIImageView`, we will only parse PDF with a fixed image size (from the PDF cropBox information). But we also support you to 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.
9090

91-
Note: Even you're on iOS/tvOS 11+, you can also use the `.pdfPrefersBitmap` context option to force us to generate the bitmap form of PDF, instead of the vector format. This can be used for some general image processing code.
91+
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 PDF.
9292

9393
+ Objective-C
9494

9595
```objectivec
9696
SDImagePDFCoder *PDFCoder = [SDImagePDFCoder sharedCoder];
9797
[[SDImageCodersManager sharedManager] addCoder:PDFCoder];
9898
UIImageView *imageView;
99-
CGSize PDFImageSize = CGSizeMake(500, 500);
100-
[imageView sd_setImageWithURL:url placeholderImage:nil options:0 context:@{SDWebImageContextPDFPrefersBitmap : @YES, SDWebImageContextPDFImageSize : @(PDFImageSize)];
99+
CGSize bitmapSize = CGSizeMake(500, 500);
100+
[imageView sd_setImageWithURL:url placeholderImage:nil options:0 context:@{SDWebImageContextImageThumbnailPixelSize : @(bitmapSize)];
101101
```
102102
103103
+ Swift
@@ -106,8 +106,8 @@ CGSize PDFImageSize = CGSizeMake(500, 500);
106106
let PDFCoder = SDImagePDFCoder.shared
107107
SDImageCodersManager.shared.addCoder(PDFCoder)
108108
let imageView: UIImageView
109-
let PDFImageSize = CGSize(width: 500, height: 500)
110-
imageView.sd_setImage(with: url, placeholderImage: nil, options: [], context: [.pdfPrefersBitmap : true, .pdfImageSize : PDFImageSize])
109+
let bitmapSize = CGSize(width: 500, height: 500)
110+
imageView.sd_setImage(with: url, placeholderImage: nil, options: [], context: [.imageThumbnailPixelSize : bitmapSize])
111111
```
112112

113113
## Export PDF data
@@ -119,15 +119,19 @@ Note: For firmware which is below iOS/tvOS 11+, UIImage does not support PDF vec
119119
+ Objective-C
120120

121121
```objectivec
122-
UIImage *image; // UIImage with vector image, or NSImage contains `NSPDFImageRep`
123-
NSData *imageData = [image sd_imageDataAsFormat:SDImageFormatPDF];
122+
UIImage *pdfImage; // UIImage with vector image, or NSImage contains `NSPDFImageRep`
123+
if (pdfImage.sd_isVector) { // This API available in SDWebImage 5.6.0
124+
NSData *pdfData = [pdfImage sd_imageDataAsFormat:SDImageFormatPDF];
125+
}
124126
```
125127

126128
+ Swift
127129

128130
```swift
129-
let image; // UIImage with vector image, or NSImage contains `NSPDFImageRep`
130-
let imageData = image.sd_imageData(as: .PDF)
131+
let pdfImage: UIImage // UIImage with vector image, or NSImage contains `NSPDFImageRep`
132+
if pdfImage.sd_isVector { // This API available in SDWebImage 5.6.0
133+
let pdfData = pdfImage.sd_imageData(as: .PDF)
134+
}
131135
```
132136

133137
## Screenshot

0 commit comments

Comments
 (0)