How to batch optimize your Exchange GAL Photos before importing to Active Directory
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 96x96 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 96x96 ~2K jpeg file:
GeSHi Error: GeSHi could not find the language powershell (using path /home/content/03/9366303/html/wp-content/plugins/codecolorer/lib/geshi/) (code 2)
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 96x96, 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:
GeSHi Error: GeSHi could not find the language powershell (using path /home/content/03/9366303/html/wp-content/plugins/codecolorer/lib/geshi/) (code 2)
After the conversion, the output folder contains optimised 96x96, 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:
Download Script and ImageMagick
As usual, if you have any problems, questions or suggestions, let me know in the comments section below.
Related posts:
- Setup and use the GAL Photos feature using Exchange 2007 [Updated]
- Enabling Outlook 2003 and 2007 to display Exchange GAL photos
- Importing Global Address List entries into a user’s Contacts folder
- Sync a text file to an Exchange distribution group
- Writing Powershell scripts that target Exchange 2007 and 2010



March 1st, 2012 - 13:55
Hi, I am trying to run the script, and everythinh seems ok, exept that there is no files in my outputfolder. I have tried to run the line with the convert.exe manually (changed some variables of course) but no files in the output folder.
It seems like convert.exe dos not run at all?
Any suggestions?
March 1st, 2012 - 14:14
PS: If I am running the line
.\bin\convert.exe -quality 100 -depth 8 -strip -thumbnail 96×96^ -gravity Center -crop 96×96+0+0 c:\xxx\OrgPic\test.jpg c:\xxx\96×96\test.jpg
from command promtp, it works..
I have tried invoke-item/expression, but no luck
October 13th, 2011 - 10:36
Hi Steve and everyone,
I’ve been using instructions from this post for a few months now. Pretty handy! Thank you for that. I just wanted to add that if you want to skip optimizng the pictures you can use a free tool from CodeTwo that I’ve just found today. It’s called Active Directory photos and lets you upload images to AD from a user’s interface – it also automatically optimizes images on the fly so you can upload pictures of any format and size. Here’s a video: http://www.youtube.com/watch?v=PkdYmuPYujY
August 28th, 2011 - 11:59
Hi,
Good post there, totally what I was looking for!
I am very interested in this topic. I researched a lot of data online to seek for valuable information on this subject. Your resource is trully informative, and I enjoyed how you summarized the info.
I am looking forward to more posts from you, and will make sure to check back later!
Thanks!
April 17th, 2011 - 00:50
Hi Terry
Do you mean how do you specify the locations when running the script, or where should you put each folder on your computer ?
For the former, it’s the -inputfolder and -outputfolder parameters followed by each respective path and for the latter, the folders can be anywhere you choose
Steve
April 17th, 2011 - 00:42
Steve, where do I set the input and output folder locations ?
March 31st, 2011 - 17:18
We have a free product available from our website that makes this very easy. http://www.exclaimer.com/products/outlook-photos/Default.aspx
March 2nd, 2011 - 00:31
Hi,
This tutorial is very useful but I do have one question. We got all of the pictures to show up in Outlook 2007 or 2010 but I am not seeing a way to have them show up in OWA. I have a lot of users who use the OWA solely and I would love for them to be able to see the pictures too. Is there a way for this to show up?
March 2nd, 2011 - 00:35
Hi Tom,
No, there’s no way currently for the pictures to show up in OWA, by some weird logic Exchange lets you import them but OWA has no capability to show the pictures. I know it’s been mentioned to the Exchange team so maybe it will make SP2.
Steve
March 2nd, 2011 - 23:10
Hey,
Thanks for the quick response and the info. Its nice that Outlook can see the photos but it is a bit of an oversight for OWA not to. Lots of people use our GAL for information on people and the photos we thought was a nice addition. Too bad this feature will now miss about half of our users.
February 25th, 2011 - 13:07
Very good work! The script is very usefull.
But I have a problem with it. I have 20 photos in the input folder (named a.jpg, b.jpg and so on) and an empty Output folder. When I run the script I only get the last picture in the Output folder. The script writes “Converting…” for all files but it look like it writes over the same file in the Output folder, leaving only one file with the “lowest” name (t.jpg). Any idé whats wrong?
Patrick
March 2nd, 2011 - 00:33
Hiya,
Not of the top of my head, does this happen even with just a couple of files?
Steve
February 3rd, 2011 - 23:11
Good tips here as I’ve just discovered adding images to the GAL. I didn’t take into consideration that adding 200+ images to AD could really add up and bloat the size of AD so thanks for bringing that to light for me.
A tool that I use for batch resizing images is FastStone Image Resizer! This little free gem is absolutely awesome! I’ve used it to resize hundreds of images straight off a digital camera in a matter of seconds. http://faststone.org/FSResizerDetail.htm is where you can get it.
February 3rd, 2011 - 23:45
Thanks Jason glad you found it useful. That’s a good tool – thanks for the link, nice to find a free GUI tool that can do the job too!
Steve
January 31st, 2011 - 21:29
Very well written. I just hacked up a GUI front end to your solution here (using primalforms community ed.) for some of the people I work with. I’ll post it a bit later tonight and link back to ya.
Thanks!
January 14th, 2011 - 17:36
Great post, Steve. I’ve been doing similar things with ImageMagik as we prepare to deploy GAL photos. A couple of your ideas helped get the file size smaller than I had before. I think I’m going to end up going with a quality of 75. 50 just seemed a little grainy for some of ours. At 75 all of our files are under 5K, but with under 400 employees, that’s not too bad — under 2MB in all.
The only option I would recommend adding is the -auto-orient option. I pull our photos from a network share that our marketing department maintains, and they have a habit of not rotating all their images when they stick them out there. Better safe than sorry!