---
title: "Accessing Image Properties Without Loading the Image"
url: https://deallocatedobjects.com/posts/accessing-image-properties-without-loading-the-image-into-memory
author: Jake Marsh
published: 2011-10-27
updated: 2013-11-16
link: http://oleb.net/blog/2011/09/accessing-image-properties-without-loading-the-image-into-memory/
topics: ["iOS Development"]
description: "I see this type of stuff a lot in other people’s code: Objective-C It’s certainly not wrong, but you are incurring a huge performance and memory usage hit just to get the width and height of an image. Enter the CGImageSource... methods."
---

# Accessing Image Properties Without Loading the Image

By Jake Marsh, October 27, 2011. HTML: https://deallocatedobjects.com/posts/accessing-image-properties-without-loading-the-image-into-memory

This is a link post about http://oleb.net/blog/2011/09/accessing-image-properties-without-loading-the-image-into-memory/

I see this type of stuff a lot in other people's code:

``` objc
UIImage *image = [UIImage imageWithContentsOfFile:@"lolcats.jpg"];
CGSize imageSize = image.size;
```

It's certainly not *wrong*, but you are incurring a huge performance and memory usage hit just to get the width and height of an image. Enter the `CGImageSource...` methods.

> As of iOS 4, the SDK includes a better solution in the form of the `CGImageSource...` set of functions, which have been available on the Mac since forever. These functions allow you to access certain image metadata without having to load the actual pixel data into memory.

[Ole Begemann](https://web.archive.org/web/20110820025141/https://twitter.com/olebegemann) has put together [a great article](http://oleb.net/blog/2011/09/accessing-image-properties-without-loading-the-image-into-memory/) explaining the ways around such performance hits, and how you can get pretty much any metadata you could want about an image, without incurring a performance or memory usage hit.
