#iOS-WebP
Most apps nowadays enhance user experience with the use of images, and one of the issues I've noticed with that is the amount of time it takes to load and image. (Not everyone has the luxury of a fast connection)
Google's WebP image format offers better compression compared to PNG or JPEG, allowing apps to send/retrieve images with smaller file sizes, reducing request times and hopefully providing a better user experience.
#Getting Started
###The CocoaPods Way
pod 'iOS-WebP', '0.1'
###The Manual Way
Include the 3 files inside the iOS-WebP
folder into your project:
UIImage+WebP.h
UIImage+WebP.m
WebP.framework
#Usage
Don't forget to #import "UIImage+WebP.h"
or #import <UIImage+WebP.h>
if you're using cocoapods.
There are 2 methods in iOS-WebP
, converting images to WebP format and converting images from WebP format.
+ (UIImage *)imageFromWebP:(NSString *)filePath;
+ (NSData *)imageToWebP:(UIImage *)image quality:(CGFloat)quality;
Using the methods are pretty easy:
//Converting To WebP
NSData *webpData = [UIImage imageToWebP:[UIImage imageNamed:@"image.jpg"] quality:75];
//Converting From WebP
UIImage *webPImage = [UIImage imageFromWebP:@"/path/to/file"]
Based off WebP-iOS-example by Carson McDonald