• Stars
    star
    141
  • Rank 259,971 (Top 6 %)
  • Language
    Objective-C
  • License
    BSD 3-Clause "New...
  • Created about 7 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

UIImage category that adds familiar HEIC encoding.

UIImageHEIC

Apple introduced widespread HEIC support with iOS 11, but the APIs for it are somewhat low level. This tiny project adds a familiar interface for encoding UIImages into HEIC data similar to what we're used to doing with JPEG or PNG data.

Installation

Add the UIImage+HEIC.h and UIImage+HEIC.m source files to your project. At the moment you must be using Xcode 9 / building with the iOS 11 SDK to use this.

Usage

Converting UIImages to HEIC

This adds a function named tj_UIImageHEICRepresentation that behaves just like UIImageJPEGRepresentation. The method returns nil in the event that HEIC encoding isn't possible on the current device.

So, where you used to have

UIImage *image = /**/;
NSData *imageData = UIImageJPEGRepresentation(image, 0.8);

You could now have

UIImage *image = /**/;
NSData *imageData = tj_UIImageHEICRepresentation(image, 0.8);
if (imageData.length == 0) {
    imageData = UIImageJPEGRepresentation(image, 0.8);
}

UIGraphicsImageRenderer Extensions

This project also adds a category to UIGraphicsImageRenderer for HEIC exporting support with fallbacks to PNG or JPEG. It's used just like you use UIGraphicsImageRenderer's existing PNG and JPEG exporting methods.

Before

UIGraphicsImageRenderer *renderer = /**/;
NSData *data = [renderer PNGDataWithActions:/**/];

After with no fallback

UIGraphicsImageRenderer *renderer = /**/;
NSData *data = [renderer tj_HEICDataWithCompressionQuality:1.0 actions:/**/];

After falling back to PNG

UIGraphicsImageRenderer *renderer = /**/;
NSData *data = [renderer tj_HEICDataFallingBackToPNGDataWithCompressionQuality:1.0 actions:/**/];

After falling back to JPEG

UIGraphicsImageRenderer *renderer = /**/;
NSData *data = [renderer tj_HEICDataWithCompressionQuality:1.0 fallingBackToJPEGDataWithCompressionQuality:1.0 actions:/**/];

Checking HEIC images

You can check if the image at a particular path is a HEIC image using tj_isImageAtPathHEIC on devices that support HEIC reading.

BOOL isHEICImage = tj_isImageAtPathHEIC(/*path to an image*/);

For lower level access you can also use tj_CGImageSourceUTIIsHEIC, which allows you to check using an image source made from data or a URL, and is also helpful if you want to immediately use the image source to perform a transformation in the event it is HEIC.

BOOL isHEICImageSource = tj_CGImageSourceUTIIsHEIC(/*image source*);

More Repositories

1

Rhea

A Mac status bar app for quickly sharing files and links.
Objective-C
91
star
2

TJDropbox

A Dropbox v2 client library written in Objective-C
Objective-C
62
star
3

TJActivityViewController

Simple customization for the iOS share sheet.
Objective-C
54
star
4

TJReadLater

Objective-C interface for popular bookmarking services
Objective-C
51
star
5

TJImageCache

A fast, easy to use Objective-C image cache
Objective-C
27
star
6

WatchActivityIndicator

An Apple Watch activity indicator
23
star
7

TJStoreReviewController

A handy wrapper around SKStoreReviewController
Objective-C
18
star
8

ViewControllerLeakDetector

Automatically find leaked view controllers.
Objective-C
17
star
9

Clippyboard

My project for Flipboard's inaugural hackathon
Objective-C
10
star
10

NSAttributedStringMarkup

Turn simple markup into NSAttributedStrings.
Objective-C
8
star
11

TJMixpanelLogger

Bare-bones Obj-C Mixpanel logger
Objective-C
6
star
12

UIImageViewAnimatedGIF

High-level wrapper around iOS 13's animated GIF playback APIs.
Objective-C
6
star
13

UILabelTapHandling

Make links in UILabels tappable.
Objective-C
5
star
14

MessageUIAdditions

Taking some of the minor pains out of the MessageUI framework
Objective-C
5
star
15

TJButton

A UIButton that does more
Objective-C
3
star
16

TJSpinny

Fullscreen activity indicator views.
Objective-C
3
star
17

TJZipCompress

Zero-dependency Objective-C zip compressor
Objective-C
2
star
18

facetype

Hobby project for the iOS showcasing Fonts
Objective-C
2
star
19

TJCollections

Handy Objective-C collections
Objective-C
2
star
20

TJNetworkActivityIndicator

A manager for UIApplication's network activity indicator.
Objective-C
2
star
21

TJExtendedNavigationPop

Really make those navigation controllers *pop*
Objective-C
1
star
22

TJTaggedPointerUtilities

1
star
23

RebaseExample

Sample code that will be used to demonstrate how git rebase works.
Objective-C
1
star
24

Thermos

Simple Thermodo thermometer app for iOS
Objective-C
1
star
25

ShareExtensionMemoryBug

Repro for a bug in iOS share extensions
Objective-C
1
star
26

Presser

A tool for cheating at Letterpress
Objective-C
1
star
27

TJFacebookProfileExpression

Open source alternative to Facebook's Profile Expression Kit
Objective-C
1
star
28

TJBackgroundTask

Convenient wrapper around UIApplication background tasks
Objective-C
1
star
29

TJScaleTipper

Rock the vote
Objective-C
1
star