Skip to content
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

Progressive image not so progressive #332

Closed
adrianslr opened this issue Dec 13, 2019 · 13 comments
Closed

Progressive image not so progressive #332

adrianslr opened this issue Dec 13, 2019 · 13 comments

Comments

@adrianslr
Copy link
Contributor

adrianslr commented Dec 13, 2019

Hello,

I'm trying to use the progressive decoding feature of Nuke.

The productImage ImageView never gets the image ..
Any clues about this?

Your example lacks in information because it only loads images from the app resources and loading from an URL is far way complicated.

Thanks in advance.

@adrianslr adrianslr changed the title Progressive Image not being so progressive Progressive image not so progressive Dec 13, 2019
@kean
Copy link
Owner

kean commented Dec 13, 2019

Hi, loading from localhost is probably simply too fast. That's why the demo uses a custom loader in which I can control the size of the data chucks and how fast they are delivered.

Please also make sure the image is actually encoded as progressive jpeg.

@adrianslr
Copy link
Contributor Author

adrianslr commented Dec 14, 2019

Hi @kean, thanks for your fast answer!

The image is actually progressive, i've tested it on a site:
image

Second, the load isn't too fast because the image has actually 70MB size.

Here is the url of the image (a smaller version): Click Me

The progress completion never gets called.
Also, from what i've see in the webserver, the image is never requested using the code i've screenshooted.
If i use the code in the example, the imageView is white for 2-3 seconds until the image is downloaded, then the image suddenly appears, no progressive loading.
Could you give further advice please?

UPDATE:

I've managed to make it work using the following code:

image

The problem is:

  • if i use a small image (10mb), it works as expected because the download time is like 0.2s.
  • if i use a large image (70mb), it doesn't work as expected. it ways 2-3 seconds until the image is downloaded, then it appears as progressive in the imageView. I think this is not the correct behaviour, i expected that the image appears as it is downloaded.

Also, what about this ?

image

Any ideas?

@kean
Copy link
Owner

kean commented Dec 15, 2019

Could you please upload the image that you are using for testing so that I could reproduce it?

@adrianslr
Copy link
Contributor Author

adrianslr commented Dec 15, 2019

Download:
https://drive.google.com/open?id=1CShVZaXu6GbUXr-HnhhfEgcNASRa1SZX (12 mb)
And the big one: https://we.tl/t-uapoN23Jg0 (70 mb)

Is there any settings that should be made for the webserver? I guess not.
If you succeed in making this work, please provide me a working example.
Thank you for your support.

@kean
Copy link
Owner

kean commented Dec 15, 2019

It works if you put it in a demo app. I tested in on an iOS simulator.

Screen Shot 2019-12-15 at 10 22 02

I didn't test on a device (assuming you are testing in on an iOS device). The image is clearly too big for an iOS device. This might be causing the issues, depending on which hardware you run it.

I would suggest not downloading images this size, downsampling them on the server. If not possible, downsampling on a device:

ImageRequest(url: url, processors: [ImageProcessor.Resize(size: .init(width: 1000, height: 1000))]

You can learn more by watching this WWDC session https://developer.apple.com/videos/play/wwdc2018/219/

I would strongly advise against rendering images this size, especially if you are doing this on iOS devices.

@adrianslr
Copy link
Contributor Author

adrianslr commented Dec 15, 2019

"It works if you put it in a demo app. I tested in on an iOS simulator."

Did you loaded it from an URL or from the app it-self?
The problem comes when the image is loaded from an URL.

Still getting nil in the progress callback even for 45kb images:

image

progress: { progress, completed, total in
print(progress?.image) => NULL

@kean
Copy link
Owner

kean commented Dec 15, 2019

Did you loaded it from an URL or from the app it-self? The problem comes when the image is loaded from an URL.

There should be no difference where data is coming from. The only difference is how fast the data is downloaded and in how many chunks it is delivered. If the download is too fast, and Nuke doesn't have enough time to produce any intermediate images, it will only produce the final image.

progress: { progress, completed, total in

Progress handler currently serves two purposes:

  • Report download progress
  • Deliver intermediate images

If none intermediate images are delivered, only the download progress is reported.

@kean
Copy link
Owner

kean commented Dec 15, 2019

how many chunks it is delivered

For example, if the image gets cached in the standard URLCache, the URLSession typically delivers it in a single chunk. The standard URLCache is enabled by default.

@adrianslr
Copy link
Contributor Author

adrianslr commented Dec 15, 2019

I'm only interested in getting intermediate images until the download finishes.
So far i didn't succeeded in producing intermediate images even for small sized images, medium or big.
What am i doing wrong?

@kean
Copy link
Owner

kean commented Dec 15, 2019

My best guess is that the download happens too fast since all the links you shared so far were referencing localhost.

Another thing that you should take into account when debugging this, is that by default, Nuke decompresses the downloaded images on the background thread. Decompression takes time. For an image this big it could be seconds.

I think that’s all the information that I can give. To debug, see ImagePipeline class. Another thing you can do is enable OSLog signposts and use profiler - they might give you and idea what is happening when the image is loaded.

@adrianslr
Copy link
Contributor Author

Ok, thanks so much for your time.

@kean
Copy link
Owner

kean commented Dec 15, 2019

No worries, if you have any specific questions, I’ll be happy to help.

@Topwiz
Copy link

Topwiz commented Nov 22, 2020

@kean
I tried downloading image with url on the demo app, but progressive image seem's it is not working.
Screen Shot 2020-11-22 at 11 35 56 AM
Screen Shot 2020-11-22 at 11 37 21 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants