Skip to content

Instantly share code, notes, and snippets.

@doctyper
Created January 8, 2011 22:11
Show Gist options
  • Save doctyper/771194 to your computer and use it in GitHub Desktop.
Save doctyper/771194 to your computer and use it in GitHub Desktop.
Batch Steps - Adding White Background for IE6
Quickie Steps (on Windows):
1. Click on Start > Run. Type "cmd" (no quotes) and press Enter. (You can also just press Windows Key + R for a shortcut).
2. Type "cd" (no quotes), press space, and drag the target folder into the command line. Press Enter.
3. Run this command:
for /f "tokens=*" %i in ('dir *.png /a:-d /s /b') do (convert "%i" -background "rgb(255, 255, 255)" "%i" & "C:\pngout.exe" "%i" -kbKGD -y "%i")
Done!
===============================================
Full Walkthrough:
Step 1: Download and install ImageMagick (OS X, Unix, or XP)
http://www.imagemagick.org/script/binary-releases.php
Step 2: Download the PNGOut command line utility (OS X, Unix, or XP)
http://advsys.net/ken/utils.htm
Step 3: cd to your image directory
Step 4a: To individually add a background to an image, you can run this command:
> convert image.png -background "rgb(255, 255, 255)" image.png
Just change 'image.png' to your image path.
To batch run on multiple files:
Step 4b: cd into image directory, then:
(Unix):
> find . -name "*.png" -exec convert '{}' -background "rgb(255, 255, 255)" '{}' \; -print
(MS-DOS):
> for /f "tokens=*" %i in ('dir *.png /a:-d /s /b') do (convert "%i" -background "rgb(255, 0, 0)" "%i")
Step 5: After conversion, you should always run PNGOut to re-compress the image. Converting will add a few kb to the image, and this step should shave off more than you've added.
Run pngout to recompress, but keep bKGD!:
(Unix):
> find . -name "*.png" -exec /path/to/pngout '{}' -kbKGD -y '{}' \; -print
(MS-DOS):
> for /f "tokens=*" %i in ('dir *.png /a:-d /s /b') do ("C:\pngout.exe" "%i" -kbKGD -y "%i")
Step 6: It's also possible to convert and immediately run PNGOut in batch mode:
(Unix):
> find . -name "*.png" -exec convert '{}' -background "rgb(255, 255, 255)" '{}' \; -exec /path/to/pngout '{}' -kbKGD -y '{}' \; -print
(MS-DOS):
> for /f "tokens=*" %i in ('dir *.png /a:-d /s /b') do (convert "%i" -background "rgb(255, 255, 255)" "%i" & "C:\pngout.exe" "%i" -kbKGD -y "%i")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment