As I’ve covered in previous articles, it’s possible to import contact photos into Active Directory and display them via the Exchange Global Address List in Outlook clients. This is fully supported against Exchange 2010 and Outlook 2010, however I’ve covered in previous articles how to import GAL photos into Exchange 2007 and how to enable your Outlook 2003 and Outlook 2007 clients to display the photos via the use of the Outlook Social Connector.
When you import pictures into the Active Directory it’s important to make sure you optimise the pictures first. The optimal dimensions for the GAL photos is 96×96 pixels, and the maximum file size for the photos is 10K. For 10,000 users, that adds at least 100MB to the database size, more so if the picture needs replicating to the Global Catalog. By properly optimizing your photos before you import, not only will the pictures look better by virtue of being the correct dimensions, but you can also squish them down to a much smaller size.
Whilst you can use Photoshop, Microsoft Paint or other tools to accomplish this, it’s actually fairly easy to batch optimize large numbers of photos at the command line, using an open source product called ImageMagick. It’s a tool you can use to create, edit and convert photos. To convert our images we only need to use a small subset of it’s conversion functionality.
Optimising a single photo
Later on in the article I’ve packaged up the script and redistributable binaries for ImageMagick, but before we get there, let’s have a quick look at the process required to convert a single image file.
First of all, we need the actual ImageMagick software. I’ve used the portable version from the ImageMagick website and from that, just copied out the convert.exe and vcomp100.dll files, because that’s all we need:
Then, with a larger file we want to convert I’ve used the following options with convert.exe to produce an optimized 96×96 ~2K jpeg file:
.\convert.exe -quality 50 -depth 8 -strip -thumbnail 96x96^ -gravity Center -crop 96x96+0+0 .\input.jpg .\output.jpg
The options are fairly straightforward. Firstly, we set the jpeg quality. The best compromise between size and quality I’ve found is 50, with 100 producing a 10K+ file, and much lower producing blocky output. The colour depth is reduced and any colour profiles or file comments are stripped out. We resize using the “thumbnail” resize option, which is a great alternative to the “resize” option that’s optimised for speed and also removes the image profile. The resize is set to a minimum of 96×96, then we do a centred crop to remove any excess pixels.
Batch optimising photos using GALBatchConvert.ps1
So now we’ve seen how to convert a single photo, what about if you’ve got a folder of 10, 100 or even 10,000? That’s (naturally) where Powershell comes in. I’ve put together a little script that you can use to perform the batch conversion.
GALBatchConvert.ps1 takes 2 mandatory parameters -InputFolder, which is the folder with the original photos and -OutputFolder, which is an empty folder to write the optimised files. As a third parameter, you can specify -Quality to override the output jpeg quality with a value between 1 and 100.
Here’s a quick example of it in use:
.\GALBatchConvert.ps1 -InputFolder .\Input -OutputFolder .\Output
After the conversion, the output folder contains optimised 96×96, 2KB jpg files and the original files are retained in the input folder, unmodified:
The full script and redistributable binaries required for ImageMagick can be downloaded below:
As usual, if you have any problems, questions or suggestions, let me know in the comments section below.