-
-
Notifications
You must be signed in to change notification settings - Fork 518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render SVG to bitmap #335
Comments
Hi @kamil3, That's an interesting use case. It is not supported directly, bu you achieve what you are describing by using pipeline = ImagePipeline {
$0.dataLoader = DataLoader(configuration: {
let conf = DataLoader.defaultConfiguration
conf.urlCache = nil // Disable disk caching built into URLSession
return conf
}())
$0.dataCache = try? DataCache(name: "com.github.kean.Nuke.DataCache")
$0.isDataCachingForOriginalImageDataEnabled = false
$0.isDataCachingForProcessedImagesEnabled = true
} The pipeline will load the image data, decode it, and then re-encode it (see But there is one issue. The "processed" images need to have at least one processor applied. What you can do is create a processor which does nothing and use it for all your requests: extension ImageProcessor {
struct Empty: ImageProcessing {
public let identifier = "EmptyProcessor"
func process(image: PlatformImage, context: ImageProcessingContext?) -> PlatformImage? {
return image
}
}
} This is not ideal, but it should work and it's highly unlikely to break in the future. |
Hi @kean, ImageDecoderRegistry.shared.register { imageDecodingContext -> ImageDecoding? in
if imageDecodingContext.request.urlRequest.url?.isSVG ?? false,
//if it's received from cache it's not SVG data anymore since it was already converted to PNG
ImageFormat.format(for: imageDecodingContext.data) == nil {
return SVGImageDecoder()
} else {
// it takes a default decoder implicilty
return nil
}
} I'm using your |
I think it would be better to extend ImageDecoderRegistry.shared.register { imageDecodingContext -> ImageDecoding? in
if ImageFormat.format(for: imageDecodingContext.data) == .svg {
return SVGImageDecoder()
}
return nil
} I was planning to release |
As far as I've been researching magic numbers for SVG do not exist, so probably I could implement another checking if it's SVG format (example thread: https://stackoverflow.com/questions/15136264/how-can-i-say-a-file-is-svg-without-using-a-magic-number). |
Here is how SDWebImage does it https://github.com/SDWebImage/SDWebImageSVGCoder/blob/master/SDWebImageSVGCoder/Classes/SDImageSVGCoder.m#L241 |
Thanks. I'll test it. Now I have another issue, I noticed 3x more memory usage using this configuration: pipeline = ImagePipeline {
$0.dataLoader = DataLoader(configuration: {
let conf = DataLoader.defaultConfiguration
conf.urlCache = nil // Disable disk caching built into URLSession
return conf
}())
$0.dataCache = try? DataCache(name: "com.github.kean.Nuke.DataCache")
$0.isDataCachingForOriginalImageDataEnabled = false
$0.isDataCachingForProcessedImagesEnabled = true
} And instead of let size = CGSize(width: 200, height: 200)
ImageRequest(url: url, processors: [ImageProcessor.Resize(size: size)]) It takes about ~5MB for each imageView (I'm rendering them in a collectionView). What is important, when using a default configuration (still with the Do you have any idea what's causing it? |
Not really. In general, downsampling results in lower memory usage. I don't currently have ideas what might be causing this. |
Hey, @kamil3. Did you figure out what was the issue with resizing? |
Hi @kean, I haven't been available until today. For now, I'd probably abandon this solution due to this issue. I'd additionally use prefetching - user experience is slightly better, but still it's not what I would like to have. |
What I've investigated so far, encoding image data is causing memory issue: |
Hi, @kamil3, any updates on this issue? |
I'm going to closes this issue since there is now a lot of outdated information here. I added "Add SVG -> Bitmap decoder" issue in a Trello board. |
Hi,
I'm using custom decoder for decoding images' data:
I noticed that it's firstly getting original data from disk cache (assuming a memory cache is empty) and then it's decoding. My custom decoding takes some time and it's noticeable. Is it any convenient way to store in a disk cache already decoded data in order to speed up loading? I mean, not to convert images every time the app launches (just for the first time).
The text was updated successfully, but these errors were encountered: