0

I am using "SVProgressHUD" for loader. When I want to load an image from url I am using async process to load the image in background. After completing the download I am updating the UI. And for that time span I am using a placeholder on the imageview and a loader with "Please wait..". But I want to use a loader like "Instagram". That means, when an image is loading from online it loads a blurry image of the original image and upon downloading the image , the blurry image show the original image.

Can any one please suggest me how can I do this?

2
  • do you own the server and control the images and server handling? Commented Jun 13, 2016 at 8:14
  • Do you have at least access to a "thumbnail" version of your image that can be easily (I mean fast) downloaded? Commented Jun 13, 2016 at 8:20

2 Answers 2

4

The stuff you are talking about is Progressive JPEG.

Progressive JPEG (PJPEG) is an image format that stores multiple, individual “scans” of a photo, each with an increasing level of detail. When put together, the scans create a full-quality image. The first scan gives a very low-quality representation of the image, and each following scan further increases the level of detail and quality. When images are downloaded using PJPEG, we can render the image as soon as we have the first scan. As later scans come through, we update the image and re-render it at higher and higher quality.

So, you have to make images loadable in this modern progressive format.You can follow a approach where every image before saving on server just convert it into appropriate progressive format.There are several tools avaiable for different type of server. E.g jpegtran

To check whether image is progressive or not you can use this tool or tool2.You can search for online tool a lot of tool is available.

Now for iOS

You can follow this tutorial

Some library
Concorde
DFImageManager

Sign up to request clarification or add additional context in comments.

1 Comment

Nuke also supports progressive JPEG starting with version 7. So does PINRemoteImage and some other libs.
0

Assuming you are in control of the hosting of the images you can host lower resolution images and make 2 fetches, one for the lower resolution, and one for the higher. If you make the lower resolution image significantly smaller in file size the fetch for it will finish before the fetch for the full image, and you populate the UIImageView with this image until such a time as you can replace it.

Purely example code would look like this:

let imageView = UIImageView()

let lowResOperation = NSBlockOperation {
    guard let imageData = NSData(contentsOfURL: NSURL(string: "https://myhost.org/low-res-image")!),
        image = UIImage(data: imageData) else { return }

    if imageView.image == nil {
        imageView.image = image
    }
}

let highResOperation = NSBlockOperation {
    guard let imageData = NSData(contentsOfURL: NSURL(string: "https://myhost.org/high-res-image")!),
        image = UIImage(data: imageData) else { return }

    imageView.image = image
}

let backgroundQueue = NSOperationQueue()
backgroundQueue.addOperations([lowResOperation, highResOperation], waitUntilFinished: true)

2 Comments

Hi, thank you for your help. But unfortunately the code is not working.
It's example code, you need to apply the concept yourself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.