4

i am trying to load images from URL to UIIMageView. it works fine, but i want to download the images at a lower resolution/size because its taking too long to load.

i have tried to use AFNetworking+UIImage class but the performance are the same.

    [iv setImageWithURL:[NSURL URLWithString:@"http://cegamers.com/wp-content/uploads/2011/06/automaton.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder-avatar"]];

anyone know how a library or some kind of way for this?

orthehelper
  • 4,009
  • 10
  • 40
  • 67
  • 3
    You can only do this server-side. If you have control of the server you could set parameters on it to specify the size and then the server would resize it before sending it down to you. – Fogmeister Jan 16 '13 at 16:46

2 Answers2

2

Generally you can't do it without server-side help. Usually you'd rely on the server generating thumbnails for you. There are image conversion proxy servers that will download the full image server-side, and serve a resized version to you.

Without any sort of server-side resizing, the options are limited and not very good.

If the image is in progressive/interlaced format then you can download only part of the file, but that will be a low-quality approximation.

Unfortunately you can't know how much data you'll need in advance, so your best bet is to either request entire image and close the TCP/IP connection when you see you've got enough data (hopefully [NSURLConnection cancel] does that) .

Or you could download some arbitrary small amount of data using HTTP Range request and then estimate how much more you need to download (it might save some bandwidth, but it will cost you latency).

I'm not aware of anything in iOS SDK that would let you inspect how many progressive scans of a partially-downloaded JPEG file you've got, so you might need to get your hands dirty with libjpeg or your own JPEG parsing.

But really it'd be easier if you could download entire image server-side and generate a proper thumbnail for it.

Kornel
  • 97,764
  • 37
  • 219
  • 309
0

Yes. If you simply add 's' to the end of the img_hash in any direct image link on imgur, then you get the small square version of it.

https://i.stack.imgur.com/sGMvI.jpg <--- Direct link
http://i.imgur.com/DkDdKs.jpg <--- Small square version. Notice the extra s

Damgaard
  • 922
  • 1
  • 9
  • 17
  • He isn't using imgur... He could re-upload it in a smaller size if thats what he wanted to do as well... –  Jan 22 '13 at 22:51