Bulk image transparency with (P.F.) ImageMagick(z)

By tabbloza | Category: Graphics | Tags: graphics, bulk, batch, image, palettes, transparency, gif, png, bmp, imagemagick | Visibility: public

ImageMagick is an open source library for image manipulation. It is not a program with a user interface, but rather a set of tools that you run through your computer's shell program, like Window's Command Prompt (cmd.exe) (or Mac's Terminal app). You may have already had to interact with these programs to debug or set up Petz! But, even if not, do not be intimidated: this tutorial will walk you through how to navigate the Command Prompt and run ImageMagick to make transparent Petz graphicz more easily. For the purposes of this tutorial, I will be assuming that you are on a Windows machine, but the commands for ImageMagick should be the same.

Set Up

Prepare your folder of images

You will want your files to be organized in a way that will minimize the change of accidentally overwriting your original files. For that reason, I suggest making subfolders like raw or original and new or out. For the purposes of this tutorial, I will show you my folder setup for each example!

Installing ImageMagick on Windows

Go to ImageMagick's website to download a version appropriate for your machine.

For Windows, download a binary release, but note that these are only compiled for Windows 10 (x86 , x64 & arm64) or newer.

Install as you would any program. But, you might notice, there is no shortcut or start program for ImageMagick! Don't worry, it is installed, but it is a command line tool only accessible through a shell program (e.g., Command Prompt).

Opening Command Prompt

In Windows, to open the Command Prompt:

  1. Go to Start
  2. Type "CMD" into Start Search
  3. Right-click "Command Prompt" result and Run as Administrator

You should see a black window like this pop up:

Opening the Command Prompt generally starts you in your Users folder, where subfolders like Documents and Downloads live. You can type and enter the command dir to see folders here.

You navigate to your files by providing their file path after typing the command cd. In my case, I want to get to my example images, which live in Documents\Games\PetzBabyz_LOCAL\Tutorialz\"Image Magickz". Notice how I put quotation marks around my Image Magickz folder? You will need to do so for any folder with spaces, otherwise the computer will not understand where you want to go.

cd Documents\Games\PetzBabyz_LOCAL\Tutorialz\"Image Magickz"

You could also navigate by going folder by folder and checking dir to see where you can go next along the way, especially if you don't know the full path to your files. If you need to back up and go out of a folder, you would type and enter cd .. (period period).

What's in my folder? I type dir and see:

 Directory of C:\Users\Tabbloza\Documents\Games\PetzBabyz_LOCAL\Tutorialz\Image Magickz

06/27/2025  08:26 AM    <DIR>          .
06/27/2025  08:26 AM    <DIR>          ..
06/27/2025  08:25 AM    <DIR>          make_transparent
06/27/2025  08:25 AM    <DIR>          tut_img
               0 File(s)              0 bytes
               6 Dir(s)  773,092,720,640 bytes free

Bulk generate GIF files with transparent backgrounds

Especially handy if you'd like to make transparent images after you've run PetzPicFactory to extract all your Petz profile pictures!

Navigate in the command line to the folder containing images that you want to make transparent. In this case, I have several GIF files. Then, I make a folder called out to hold the output files. We will ask ImageMagick to loop through out input images, extract the top-left most pixel from each image, and set all pixels of the same color to a transparent alpha. These will be saved to output images in out/.

cd make_transparent
mkdir out
for %f in (*.gif) do @for /f %c in ('magick identify -format "%%[pixel:p{0,0}]" "%f"') do magick "%f[0]" -alpha on -transparent %c "out\%~nf.gif"

Comments

No comments yet. Be the first to say something!

Log in to post a comment.