Kingfisher: how can downoad SVG image url with kingfisher

Created on 29 Jun 2019  ·  4Comments  ·  Source: onevcat/Kingfisher

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

Issue Description

What

[Tell us about the issue]

Reproduce

[The steps to reproduce this issue. What is the url you were trying to load, where did you put your code, etc.]

Other Comment

[Add anything else here]

Most helpful comment

This is how I used. I have created SVG Image Processor and for data parsing I have used SVGKit.

import UIKit
import Kingfisher
import SVGKit

public struct SVGImgProcessor:ImageProcessor {
    public var identifier: String = "com.appidentifier.webpprocessor"
    public func process(item: ImageProcessItem, options: KingfisherParsedOptionsInfo) -> KFCrossPlatformImage? {
        switch item {
        case .image(let image):
            print("already an image")
            return image
        case .data(let data):
            let imsvg = SVGKImage(data: data)
            return imsvg?.uiImage
        }
    }
}

All 4 comments

SVG is not built-in supported in Kingfisher. You need to create your own processor and maybe use some other package (like this) to convert data and show it as an UIImage or NSImage.

This is how I used. I have created SVG Image Processor and for data parsing I have used SVGKit.

import UIKit
import Kingfisher
import SVGKit

public struct SVGImgProcessor:ImageProcessor {
    public var identifier: String = "com.appidentifier.webpprocessor"
    public func process(item: ImageProcessItem, options: KingfisherParsedOptionsInfo) -> KFCrossPlatformImage? {
        switch item {
        case .image(let image):
            print("already an image")
            return image
        case .data(let data):
            let imsvg = SVGKImage(data: data)
            return imsvg?.uiImage
        }
    }
}

Use SVGImgProcessor like this:

imageView.kf.setImage(with: imURL, options: [.processor(SVGImgProcessor())])

AppDelegate.isForWorker
what is that? what should I do with this

Use SVGImgProcessor like this:

imageView.kf.setImage(with: imURL, options: [.processor(SVGImgProcessor())])

Was this page helpful?
0 / 5 - 0 ratings