Resize p
Posted: 2016-10-31T07:35:51-07:00
can someone help me to add proportional resize code to this script: for example 1000xproportional and resize it again with white background if the image is not 1000x1000
like yc:white +swap -gravity center -composite \
like yc:white +swap -gravity center -composite \
Code: Select all
@ECHO OFF
set resizeSize=1000x1000
set dirCnt=0
set tmpCnt=0
set convert_exe=C:\Program Files\ImageMagick-6.8.0-Q16\convert.exe
set foldername=%1
REM remove double quote from string
set distfolder=%foldername%"\1000x1000"
set distfolder=%distfolder:""=%
REM =(1)============< CHECK PATH MAGIC >============================================
IF NOT EXIST "%convert_exe%" (
echo ImageMagick path is incorrect. You need to set it up in batch file!
echo Current value: %convert_exe%
pause
exit 4
)
REM =(2)============< COUNT JPG files >===================================================
for /F "usebackq delims=" %%i in (`dir /a:-d /b %foldername%\*.jpg`) do set /a dirCnt+=1
IF (%dirCnt%) EQU (0) (
call set foldername=%%~dp1
for /F "usebackq delims=" %%i in (`dir /a:-d /b %%foldername%%\*.jpg`) do set /a dirCnt+=1
)
IF (%dirCnt%) EQU (0) (
echo JPG files not found in folder "%foldername%". Exiting.
pause
EXIT 1
)
echo Found %dirCnt% JPG files in folder %foldername%.
REM =(3)===============< MAKE WEB DIR >===============================
set tmpCnt=0
for /F "usebackq delims=" %%i in (`dir /B /A:D %foldername%`) do (
if %%i EQU web600 set /a tmpCnt+=1
)
IF (%tmpCnt%) EQU (0) md %foldername%\1000x1000
REM ==============================================================
set tmpCnt=0
for /F "usebackq delims=" %%i in (`dir /B /A:D %foldername%`) do (
if %%i EQU web600 set /a tmpCnt+=1
)
IF (%tmpCnt%) EQU (0) (
echo Error! Can't create folder "%foldername%\1000x1000".
pause
EXIT 2
)
REM ==============================================================
echo Resizing JPG files in %foldername%:
chdir /D %foldername%
set tmpCnt=0
for /F "usebackq delims=" %%i in (`dir /a:-d /b %foldername%\*.jpg`) do (
set /a tmpCnt+=1
call echo Proceed file %%tmpCnt%% from %%dirCnt%%: "%%i"
"%convert_exe%" "%%i" -interpolate bicubic -filter lagrange -set option:filter:support 2.0 -set option:filter:win-support 12 -set option:filter:lobes 8 -resize %resizeSize% -quality 95 ".\1000x1000\%%i"
)
echo ""
echo Resizing is done, check folder web for results!
echo ""
pause