Matt Gemmell

CHANGER is available now!

An action-thriller novel — book 1 in the KESTREL series.

★★★★★ — Amazon

How to get a Quick Look preview as an NSImage

development & source 1 min read

I wrote a quick category on NSImage allowing you to get an image containing a Quick Look preview of the file at a given path. You can specify the size, and whether the preview should be rendered as an icon (i.e. with a document border, drop-shadow, page-curl and file type/extension label superimposed). So, you can get both Finder-style preview icons, and also full-size previews like in the Quick Look panel.

If Quick Look can’t generate a preview for the specified file, you’ll be given the file’s Finder icon instead (which is how the Quick Look panel itself behaves in Leopard). Source is available on the Cocoa Source Code page, and includes a Read Me and the usual license document. Needless to say, this code requires Leopard or later.

Enjoy. :)

Update: Now much more efficient, thanks to a new Leopard-only method pointed out by Troy Stephens at Apple - thanks to Troy for that. You can also get the latest version of this code from the MacCode repository at Google Code.