Generating Thumbor URLs on iOS
Faster image loading, better caching, easy.
Written by Jim Puls.
Heads up, we’ve moved! If you’d like to continue keeping up with the latest technical content from Square please visit us at our new home https://developer.squareup.com/blog
A little while back, we talked about dynamic images with Thumbor.
To recap:
Thumbor is an open-source, on-demand image service which allows for server-side cropping, resizing, and compositing of images. This is particularly useful for applications where the density and resolution of the target screen can vary wildly. Rather than downloading a large image and scaling it to fit the display, the image is requested at the exact desired size and the server does the work on-demand to resize it before delivering.
To go with our Pollexor library on Android, today we’ve open-sourced ThumborURL to do the same on iOS.
It’s really slick and very easy to use. In five lines of code, you can request a resized version of an image:
NSURL *baseURL = [NSURL URLWithString:@"http://my.thumbor.server"];
NSURL *imageURL = [NSURL URLWithString:@"http://www.google.com/images/srpr/logo3w.png"];
TUOptions *opts = [[TUOptions alloc] init];
opts.targetSize = CGSizeMake(100, 100);
NSURL *u = [NSURL TU_secureURLWithOptions:opts imageURL:imageURL baseURL:baseURL securityKey:@"use-a-better-security-key-than-this"];
Try it out! Let us know what you think.