I need to change the palette (.pal file) of multiple images at once. How can I do this?

Does anyone know anyway to change the palette of multiple images at once? I have tried many different programs and there has got to be a better way than opening each image, clicking import palette and then finding the .pal file and then saving the file. I feel like a computer could automate this but I haven't found a way to do it. I use irfanview and GIMP for batch processing images like cropping and renaming. Now I need a uniform palette to be imported and applied/saved to the image. I have thousands of images I need to change the palette and I am hitting my head against a rock. Maybe even a key record that copies my keystrokes then does it over and over again. There just has got to be a better way. Please any ideas will help!


First you create a new palette by using one of the photos that already has the color plaette applyed to it.

ffmpeg -i SomeImage.png -vf "palettegen" MyPalette.png

Then you copy the following code to notepad and save it with the name you want but with a *.bat extension. At the "set Pal=" part you specify where you saved your color palette. Next you drag and drop the folder where the pictures are that you want to apply the color palette to are to the batch file.

For each image there should be created a new image with the same name as the old one except with "_new" in the name.

@echo off

:: Please inform the color palete you want to use here:
set Pal=%userprofile%\desktop\Palette.png

if exist "%~1\" (set "Folder=%~1") else (exit)

pushd "%Folder%"

for /f "delims=" %%a in ('dir /b *.jpg *.png *.bmp') do ffmpeg -i "%%a" -i "%Pal%" -lavfi "paletteuse" "%%~na_new%%~xa"

In this example I used a color palete with gray style colors only to make the difference more obvious:

palette.gif

Update: Using a Batch file with Irfanview:

@echo off

:: Please inform the color palete you want to use here:
set Pal=%userprofile%\desktop\playpal.pal

:: Please inform the path to irfranview here:
set Irfran=C:\Program Files\IrfanView\i_view64.exe

if exist "%~1\" (set "Folder=%~1") else (exit)

pushd "%Folder%"

for /f "delims=" %%a in ('dir /b *.jpg *.png *.bmp') do "%Irfran%" "%%a" /import_pal="%Pal%" /convert="%%~na_new%%~xa"

I tested this with a color palete that I download from here: lospec.com