Skip to content

Instantly share code, notes, and snippets.

@dgyesbreghs
Created October 27, 2016 18:27
Show Gist options
  • Save dgyesbreghs/9b18494ea2002a6fba51954e86542b6a to your computer and use it in GitHub Desktop.
Save dgyesbreghs/9b18494ea2002a6fba51954e86542b6a to your computer and use it in GitHub Desktop.
Encode UIImage to Base64 string
//
// NSString+Base64.h
// Pods
//
// Created by Dylan Gyesbreghs on 27/10/2016.
//
//
#import <Foundation/Foundation.h>
@interface NSString (Base64)
- (UIImage *)base64Decoding;
@end
//
// NSString+Base64.m
// Pods
//
// Created by Dylan Gyesbreghs on 27/10/2016.
//
//
#import "NSString+Base64.h"
@implementation NSString (Base64)
- (UIImage *)base64Decoding
{
NSData *base64Data = [[NSData alloc] initWithBase64EncodedString:self options:NSDataBase64DecodingIgnoreUnknownCharacters];
return [UIImage imageWithData:base64Data];
}
@end
//
// UIImage+Base64.h
// Pods
//
// Created by Dylan Gyesbreghs on 27/10/2016.
//
//
#import <UIKit/UIKit.h>
@interface UIImage (Base64)
- (NSString *)base64Encoding;
@end
//
// UIImage+Base64.m
// Pods
//
// Created by Dylan Gyesbreghs on 27/10/2016.
//
//
#import "UIImage+Base64.h"
@implementation UIImage (Base64)
- (NSString *)base64Encoding
{
return [UIImagePNGRepresentation(self) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment