Last active
November 6, 2018 17:19
-
-
Save re3turn/a2d27b360d5e70ca83794541457ef484 to your computer and use it in GitHub Desktop.
PNGの種類を判別するバッチ
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 | |
setlocal | |
set "MAGICK=C:\Program Files\ImageMagick-7.0.8-Q16\magick.exe" | |
set "PNG_FILE=%1" | |
if "PNG_FILE" == "" ( | |
call :usage | |
exit /b 1 | |
) | |
echo "%PNG_FILE%" | find ".png" > nul | |
if %ERRORLEVEL% neq 0 ( | |
call :usage | |
exit /b 1 | |
) | |
"%MAGICK%" identify -verbose %PNG_FILE% > __png__.txt | |
for /f "delims=" %%A in ('findstr color_type __png__.txt') do set COLOR_TYPE=%%A | |
for /f "delims=" %%A in ('findstr "Alpha: " __png__.txt ^| findstr bit') do set ALPHA=%%A | |
del __png__.txt | |
if "%COLOR_TYPE%"==" png:IHDR.color_type: 6 (RGBA)" ( | |
set PNG_TYPE=PNG32 | |
) else if "%COLOR_TYPE%"==" png:IHDR.color_type: 2 (Truecolor)" ( | |
set PNG_TYPE=PNG24 | |
) else if "%COLOR_TYPE%"==" png:IHDR.color_type: 3 (Indexed)" ( | |
set PNG_TYPE=PNG8 | |
) else ( | |
set PNG_TYPE=UNKNOWN | |
) | |
if "%PNG_TYPE%"=="PNG32" ( | |
if "%ALPHA%"==" Alpha: 8-bit" ( | |
echo PNG32, RGB+alpha, Transparent | |
) else if "%ALPHA%"==" Alpha: 1-bit" ( | |
echo PNG32, RGB+alpha | |
) else ( | |
echo PNG32, UNKNOWN | |
) | |
) else if "%PNG_TYPE%"=="PNG24" ( | |
if "%ALPHA%"=="" ( | |
echo PNG24, RGB | |
) else ( | |
echo PNG24, UNKNOWN | |
) | |
) else if "%PNG_TYPE%"=="PNG8" ( | |
if "%ALPHA%"=="" ( | |
echo PNG8, RGB | |
) else if "%ALPHA%"==" Alpha: 8-bit" ( | |
echo PNG8 RGB+alpha Alpha Channel | |
) else if "%ALPHA%"==" Alpha: 1-bit" ( | |
echo PNG8, RGB+alpha, Index Transparent | |
) else ( | |
echo PNG8, UNKNOWN | |
) | |
) else ( | |
echo Unknown png format | |
) | |
exit /b | |
:usage | |
echo %~n0 ^<pngfile^> | |
exit /b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment