Tips and Tricks About Computers, Web Development, Linux, the Internet and the Like
Batch images conversion – color to transparency from the linux terminal
I’ve been re-theming and old forum and the themes that are available are a little less than perfect for our needs. I found a few suitable templates but it still results in me creating a mash-up. Some of the images (though gif) set the image background color to that of the site background. As I was using a different color, this obviously looked bad but I wasn’t about to manually edit all the files to give them transparency.
Being aware of the amazing command line tool for Linux, ImageMagick, I set out to find a tool to help me. I found a transparency flag, calculated the RGB values with the eyedropper in GIMP, then after a test run, I through it in a for loop.

So a directory down from my image source, I created a folder called “new” and ran the following color and like magic, they were all converted.
for image in *.gif; do convert -transparent 'RGB(48,71,94)' $image ../new/$image; done
| Print article | This entry was posted by Tyler Mulligan on March 31, 2009 at 7:21 pm, and is filed under Bash, Linux, Software, Ubuntu, open source. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 9 months ago
For those of you stuck using windows and DOS, like me, a batch file containing:
for %%x in (*.png) do convert -transparent “RGB(255,0,255)” %%x ../new/%%x
will do the trick.
about 7 months ago
Very nice trick