Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fummicc1/asyncdownsamplingimage
Extended AsyncImage to perform down sampling when downloading image
https://github.com/fummicc1/asyncdownsamplingimage
asyncimage downsampling swiftui
Last synced: 3 months ago
JSON representation
Extended AsyncImage to perform down sampling when downloading image
- Host: GitHub
- URL: https://github.com/fummicc1/asyncdownsamplingimage
- Owner: fummicc1
- License: mit
- Created: 2023-01-30T17:28:10.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-16T12:47:04.000Z (3 months ago)
- Last Synced: 2024-10-18T16:16:30.759Z (3 months ago)
- Topics: asyncimage, downsampling, swiftui
- Language: Swift
- Homepage: https://medium.com/@fummicc1/asyncimage-that-can-perform-downsampling-947c11da66d1
- Size: 2.94 MB
- Stars: 16
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AsyncDownSamplingImage
`AsyncDownSamplingImage` is a SwiftUI component that has similar interface to original [AsyncImage](https://developer.apple.com/documentation/swiftui/asyncimage) and can perform downsampling so that we can reduce the memory buffer to store image data fetched from a server.
## Impact of Downsampling
with downsampling, we can reduce the huge amount of memory use like the below.
|default AsyncImage| AsyncDownSamplingImage (×2~3 efficient) |
|---|---|
|||Moreover, the more the number of images increases, the more we can get the benefit.
Below is a comparision when I scrolled and show 100/1000 high resolution images (1000×1000px).
With AsyncDownSamplingImage, we changed Image size `1000x1000` into `160x160` which is same size as rendered `Image`.|100 Default AsyncImages| 100 AsyncDownSamplingImages (×10~ efficient) |
|---|---|
||||1000 Default AsyncImages| 1000 AsyncDownSamplingImages (×30~ efficient) |
|---|---|
|||## Installation
```swift
.package(url: "https://github.com/fummicc1/AsyncDownSamplingImage.git", from: "1.1.0")
```## How to use AsyncDownSamplingImage
`AsyncDownSamplingImage` aims to be used in a similar way to `AsyncImage` even if the implementation is different.
```swift
public init(
url: Binding,
downsampleSize: Binding,
content: @escaping (Image) -> Content,
placeholder: @escaping () -> Placeholder,
fail: @escaping (Error) -> Fail
)
``````swift
public init(
url: URL?,
downsampleSize: Binding,
content: @escaping (Image) -> Content,
fail: @escaping (Error) -> Fail
)
``````swift
public init(
url: URL?,
downsampleSize: CGSize,
content: @escaping (Image) -> Content,
fail: @escaping (Error) -> Fail
)
```You can use `AsyncDownSamplingImage` in the following way.
```swift
@State private var url = URL(string: "https://via.placeholder.com/1000")
@State private var size: CGSize = .init(width: 160, height: 160)...
AsyncDownSamplingImage(
url: url,
downsampleSize: size
) { image in
image.resizable()
.frame(width: size.width, height: size.height)
} fail: { error in
Text("Error: \(error.localizedDescription)")
}
```## How to use IncrementalImage
IncrementalImage is a component that can load image data in chunks.
The size of buffer is set by `bufferSize` parameter in bytes unit.```swift
let url = URL(string: "https://via.placeholder.com/1000")IncrementalImage(url: url, bufferSize: 1 * 1024)
```## DocC
[Documentation](https://fummicc1.github.io/AsyncDownSamplingImage/documentation/asyncdownsamplingimage/) generated by DocC is available (still working in progress).
## Contributing
Pull requests, bug reports and feature requests are welcome 🚀
## License
[MIT LICENSE](https://github.com/fummicc1/AsyncDownSamplingImage/blob/main/LICENSE)
## Reference
- https://medium.com/@zippicoder/downsampling-images-for-better-memory-consumption-and-uicollectionview-performance-35e0b4526425