How to batch optimize your Exchange GAL Photos before importing to Active Directory

imageAs 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
Converting C:\Users\steve\Documents\Input\isabelle.jpg
Converting C:\Users\steve\Documents\Input\lisa.jpg
Converting C:\Users\steve\Documents\Input\steve.jpg
Converting C:\Users\steve\Documents\Input\steve2.jpg

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:

Download Script and ImageMagick

As usual, if you have any problems, questions or suggestions, let me know in the comments section below.

29 thoughts on “How to batch optimize your Exchange GAL Photos before importing to Active Directory

  1. I use “-quality 50 -depth 8 -thumbnail 96×96> -background white -gravity center -extent 96×96” to get the full picture in the 96*96 format. The geometry operator > in 96×96> is used to shrink an image only if its dimension(s) are larger than the corresponding width and/or height arguments.

  2. Hello Stevie,

    Thank you for this info. Do you by the way know why this dimension of 96*96 px is recommended. Most pictures ar portrait rectangulars and not square. I also found out, that -strip is not necessary. it is implemented via -thumbnail

      • Thanks for your answer. It’s just, that I found out that with your parameters in the convert.exe, people tend to loose the top of their heads, if they use a portrait picture. I will try it if a picture with a size of 50*96 is also visible in oulook 2010. My aim is to make a program that load the profile pictures in SharePoint 2007 to Active directory thumbnails. Almost ready, but have this little issue left.

        • Thanks – to be honest it’s not something I’d considered. The key factor was trying to minimise the size of the file in AD whilst still making sure the image met the requirements for Outlook.

          I’m much keener on 2013’s method – especially allowing them to upload and manage their own photo in OWA.

  3. Can you bind this with an LDAP script to:
    1) Look at the source folder of photos and create an index/array
    2) Search through AD for users with Photos that are larger than 96×96 pixels.. output these pictures to the source folder (assuming no overwrite necessary)
    3) Process the files left in the source folder, resized to 96×96 px
    4) LDAP import these pictures to users that match the filename

    Assuming this can be done… we have got:
    A shared folder for recruitment to dump pics of new starters in.. existing photos in the GAL are re-sized to reduce the footprint.. and we are using powershell!

    I made part of this in VBS; but had a real issue with the VBS side of using Image Manipulation Class Librarys to get the whole thing working optimumally. I gave up in the end.. here is the code I started with:

  4. I am looking for a solution which can be rolled out to end users to upload their photo to AD which can then be available in Outlook 2010. Like it should give a web interface for user to logon with their domain credentials and then add\edit their photo.

  5. Pingback: Lync corporate photo update script « marjus`s field notes « JC’s Blog-O-Gibberish

  6. Pingback: How to batch optimize your Exchange GAL Photos to Active Directory « MidThought's

  7. 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?

    • 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

  8. 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:

  9. 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!


  10. Pingback: Absurd» Blog Archive » optimise photo

  11. 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


  12. 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?

    • 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.


      • 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.

  13. 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?


  14. Pingback: » Visualizzare le foto in Outlook 2010 e nella GAL di Exchange 2010 icubed portal

  15. 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. is where you can get it.

  16. Pingback: Outlook 2010: Photo Sizing Tool | The Little Things

  17. 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.


  18. 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! :)

  19. Pingback: Tweets that mention How to batch optimize your Exchange GAL Photos before importing to Active Directory --

Leave a Reply