Created
March 3, 2017 10:49
-
-
Save altbdoor/fa347b1297e8e5e835df47d3f5ee90fc to your computer and use it in GitHub Desktop.
Compiles all PNG images in folder into a JPG image set
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: set path to the graphicsmagick folder, get gm from | |
:: https://sourceforge.net/projects/graphicsmagick/files/graphicsmagick-binaries/ | |
set graphicsmagick_path=C:\Program Files (x86)\GraphicsMagick-1.3.25-Q8\ | |
:: the maximum width of the image set | |
set image_set_width=1200 | |
:: the resize filter, please check | |
:: http://www.graphicsmagick.org/GraphicsMagick.html#details-filter | |
set image_resize_filter=Lanczos | |
:: the background and border color of the image | |
set image_background_color=black | |
set image_border_color=black | |
:: the border size, separating each image | |
set image_border_size=4 | |
:: ======================================== | |
set PATH=%PATH%;%graphicsmagick_path% | |
set original_path=%cd% | |
set copy_path=%temp%\rsz%random%.tmp | |
set all_img= | |
set img_count=0 | |
if exist "%copy_path%" ( | |
rmdir /s /q "%copy_path%" | |
) | |
mkdir "%copy_path%" | |
copy "%original_path%\*.png" "%copy_path%" > nul | |
cd "%copy_path%" | |
for %%f in (*.png) do call :process_img "%%f" | |
echo Combining all images... | |
set "output_path=%original_path%\imageset.jpg" | |
gm.exe convert %all_img% -append -quality 95 -strip "%output_path%" | |
goto :eof | |
:: ======================================== | |
:process_img | |
set current_img=%1 | |
set "all_img=%all_img% %current_img%" | |
for /f "delims=" %%i in ('gm.exe identify -format %%w %%current_img%%') do set img_w=%%i | |
for /f "delims=" %%i in ('gm.exe identify -format %%h %%current_img%%') do set img_h=%%i | |
echo Processing %current_img%, dimensions %img_w%x%img_h% | |
set border_args= | |
if %image_border_size% gtr 0 ( | |
if %img_count% neq 0 ( | |
set "border_args=-bordercolor ""%image_border_color%"" -border ""0x%image_border_size%"" -gravity south -chop ""0x%image_border_size%"" " | |
) | |
) | |
set /a "img_count=%img_count%+1" | |
if %img_w% gtr %image_set_width% ( | |
echo Width larger than %image_set_width% | |
gm.exe convert %current_img% -filter "%image_resize_filter%" -resize "%image_set_width%x" %border_args% %current_img% | |
) | |
if %img_w% lss %image_set_width% ( | |
echo Width smaller than %image_set_width% | |
gm.exe convert %current_img% -background "%image_background_color%" -gravity center -extent "%image_set_width%x%img_h%" %border_args% %current_img% | |
) | |
if %image_border_size% gtr 0 ( | |
if %img_w% equ %image_set_width% ( | |
echo Width equals %image_set_width% | |
gm.exe convert %current_img% %border_args% %current_img% | |
) | |
) | |
echo ==================== | |
goto :eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment