Skip to content

Instantly share code, notes, and snippets.

@goldbattle
Last active December 30, 2015 10:59
Show Gist options
  • Save goldbattle/7819139 to your computer and use it in GitHub Desktop.
Save goldbattle/7819139 to your computer and use it in GitHub Desktop.

How-To Guide

Needs imagemagick for command line image conversions. Make sure you can run the commands in your command line.

Simple directory layout:

\Batch_Convert.bat (the script downloaded from here)
\items             (all base greyscale images go here)
  \arrow
    \arrow_fletching.png
    \arrow_head.png
    \arrow_shaft.png
  \axe
  \battleaxe
  \etc..
\overlays          (all overlay images go here)
  \alumite.png
  \ardite.png
  \blueslime.png
  \etc..

Run the batch file from the command line or by double clicking it. Please note, that because windows is stupid, you need to not have any spaces in the directories Do not have spaces in the directory i.e it needs to be in someplace like C:\Batch_Overlay\

For files to test on, check out the soartex repo here: Example files, and linux method

Enjoy!

:: Name: Batch Converter
:: Author: GoldBattle
:: Copyright: Copyright (c) 2009-2015, Soartex Graphics <http://soartex.net/>
:: License: All Rights Reserve
:: Support: support@soartex.net
@echo OFF
:: Ask for filename choices
echo.
echo What filename order do you want?
echo 1: overlay filename
echo 2: filename overlay
set /p one_or_two=Your Choice:%=%
echo.
:: Set our system properties
setlocal disableDelayedExpansion
:: Get the overlay files
cd overlays
for /f "tokens=1* delims=:" %%A in ('dir /s /b^|findstr /n "^"') do (
:: Add overlay file to array
set "file.%%A=%%B"
set "file.count=%%A"
)
cd ..
:: Loop through overlays, and overlay them
setlocal enableDelayedExpansion
for /l %%N in (1 1 %file.count%) do call :Over !file.%%N!
:: End the script
goto End
:Over
cd items
:: Loop through item sub-directorys
for /F %%x IN ('dir /a:d /b') do (
:: Loop through files
for /F %%a in ('dir %%x /b') do (
:: Run the commands needed
call :Run %%x %%a %1
)
)
cd ..
:: Send back to the overlay loop
goto :eof
:Run
:: Orginal file, and overlay paths
set f=%CD%\%1\%2
set o=%3
:: Filenames, of the item, and overlay
for /F "delims=" %%A in ("%3") do set "FILENAME=%%~nA"
for /F "delims=" %%A in ("%f%") do set "FILENAME2=%%~nA"
:: Our output directory
set ud=%CD%\..\output\%1\
:: Have the corrent filename
if %one_or_two% == 1 set uf=%CD%\..\output\%1\%FILENAME%_%FILENAME2%.png
if %one_or_two% == 2 set uf=%CD%\..\output\%1\%FILENAME2%_%FILENAME%.png
:: Debug print out
if %one_or_two% == 1 echo [Overlay]: %FILENAME% [File]: %FILENAME%_%FILENAME2%.png
if %one_or_two% == 2 echo [Overlay]: %FILENAME% [File]: %FILENAME2%_%FILENAME%.png
:: Make the directory if it isn't already
if not exist %ud% mkdir %ud%
:: Convert the file, overlay using mask, this is just a white file (suppress errors)
convert %f% %o% %f% -colorspace Transparent -alpha extract -compose Overlay -composite -alpha on %uf% >nul 2>&1
:: Use the created mask to mask the real overlay and then output it again (suppress errors)
convert %f% %o% %uf% -colorspace Transparent -compose Overlay -composite %uf% >nul 2>&1
:: Send back to the loop
goto :eof
:End
PAUSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment