Modified version of Apple's WWDC 2013 UIImage category.