環境
OS:Windows
ImageMagic7以降
注意
ファイル名に半角スペースが含まれている場合エラーになります
作成したバッチファイルは画像のあるフォルダに入れて実行してください
トリミングした画像はPNG画像になります
変数preにはファイル前置詞を指定できます
CircleConv.bat
@echo off setlocal enabledelayedexpansion set pre=_ type nul > list.txt for %%i in (*.jpg) do ( magick identify "%%i" >> list.txt ) for /f "tokens=1,3" %%a in (list.txt) do ( for /f "tokens=1,2 delims=x" %%x in ("%%b") do ( set /a cx=%%x/2 set /a cy=%%y/2 if /i %%x gtr %%y ( set top=0 set left=!cx! set harfx=0 set /a harfy=%%y/2 set size=%%y set /a cutleft=%%x-!size! set /a cutleft=!cutleft!/2 set cuttop=0 ) else ( set top=!cy! set left=0 set /a harfx=%%x/2 set harfy=0 set size=%%x set cutleft=0 set /a cuttop=%%y-!size! set /a cuttop=!cuttop!/2 ) set /a harf=!size!/2 magick -size !size!x!size! xc:none -draw "circle !harf!,!harf! !harfx!,!harfy!" _mask_%%a.png magick %%a -crop "!size!x!size!+!cutleft!+!cuttop!" _ex_%%a.png magick _ex_%%a.png _mask_%%a.png -compose CopyOpacity -composite %pre%%%%a.png del _ex_%%a.png del _mask_%%a.png ) ) del list.txt