Use QuickLook for Easy and Beautiful File Thumbnails
Recently, I was creating a web page with a list of various PDFs available for download. I wanted an icon users could click to download the file, but popping in a generic PDF icon seemed…well, boring. Wouldn't it be great, thought I, to use the gorgeous icon previews that the Mac OS X Finder creates instead? While there isn't any obvious way to do this in the Finder, a system tool called qlmanage does the work for you. Read on to see how to use it to create previews from PDFs, images, text, or documents in Pages, Numbers, Keynote, Word, Excel, PowerPoint, HTML, and more!
Coming Soon: I am writing a GUI app that will make this process laughably easy, as well as allow you to convert multiple files, see previews, and more! Stay tuned.
The magic all happens on the command line. Here's the command:
qlmanage -tif scaleFactor -o /path/to/outputdirectory/ /path/to/file.ext
What does all this mean?
- The -t flag tells qlmanage to create a thumbnail instead of a preview. A preview would be the full-size view you get when you do QuickLook in the Finder, which is not what we want.
- The -i flag is where the magic happens. A thumbnail alone is just a scaled-down version of the document, but using this flag adds the icon "effects" like the binder around the PDF icon.
- The -s flag sets what size the output should be. The default is 128x128 but you can get any size you want (e.g. 32, 16, 512, 256)
- The -o flag makes the output go to a file, rather than a shell image output. Specify the output directory after this flag.
- Finally, specify the path to the file you want to generate the thumbnail for. Any file that creates a custom thumbnail in the Finder should work. If a thumbnail cannot be generated, you'll get a message indicating that no thumbnail was created.
That's really all there is to it! To get more information about how qlmanage works, type qlmanage -h to display the help.
No matter what, this trick will only work in Mac OS X 10.5 "Leopard" or later, because QuickLook didn't exist before then! I have tested it in Snow Leopard with success. Initial tests with Leopard on PowerPC have shown that it does not work because Leopard's (PPC) qlimage does not support the -o flag (though it does support the -i flag, despite it not being documented), though I have not yet had the opportunity to test on Leopard Intel. I'll report back with a solution for these systems if one exists.
This will work with any file that QuickLook can handle — including QuickLook plugins! For example, here's a preview I created of the SkySafari IPA using the quicklook-ipa plugin:
Be sure to check out QuickLook plugin repositories like the QuickLook Plugins List to generate thumbnails for even more files.
If you've played around with this tool and found anything else of note, please leave a comment!
[Thanks to this thread on macscripter.net for the inspiration]