http://www.imagemagick.org/Usage/resize/#fill 

 

@ECHO OFF

REM ===========变量定义============
REM 裁减后尺寸请配置到output.config,用空格分割 文件名 长 宽
REM 源文件,不带后缀(默认后缀都是.jpg)
SET IMAGE_FILE=Penguins
REM 裁减重心
SET GRAVITY=center
REM convert.exe的路径
SET CONVERT_PATH=convert.exe
REM option1:保持原图比例剪裁 ; option2:不保持原图比例压缩
REM 示例:::option1:保持原图比例剪裁
REM .\ImageMagick6.7.9\convert Penguins.jpg -gravity center -resize 300x -resize x100^< -crop 300x100+0+0 +repage test_300x100.jpg
REM ::option2:不保持原图比例压缩
REM convert Penguins.jpg -resize 500x120! test_500x120.jpg
SET OPTHON=OPTION2
REM ===========执行代码============
if "%OPTHON%"=="OPTION2" GOTO OPTION2
:OPTION1
@ECHO option1:保持原图比例,有剪裁   -crop %%jx%%k+0+0 +repage 
for /f "tokens=1,2,3 delims= " %%i in (output.config) do echo %%i %%j %%k
for /f "tokens=1,2,3 delims= " %%i in (output.config) do (
@ECHO %CONVERT_PATH% %IMAGE_FILE%.jpg -gravity %GRAVITY% -resize %%jx -resize x%%k^^^< -crop %%jx%%k+0+0 +repage %%i_%%j-%%k.jpg
 %CONVERT_PATH% %IMAGE_FILE%.jpg -gravity %GRAVITY% -resize %%jx -resize x%%k^^^< -crop %%jx%%k+0+0 +repage %%i_%%j-%%k.jpg
)
GOTO THE_END
:OPTION2
@ECHO option2:不保持原图比例压缩,不裁剪
for /f "tokens=1,2,3 delims= " %%i in (output.config) do echo %%i %%j %%k
for /f "tokens=1,2,3 delims= " %%i in (output.config) do (
@ECHO %CONVERT_PATH% %IMAGE_FILE%.jpg -gravity %GRAVITY% -resize %%jx%%k! %%i_%%j-%%k.jpg
%CONVERT_PATH% %IMAGE_FILE%.jpg -gravity %GRAVITY% -resize %%jx%%k! %%i_%%j-%%k.jpg
)
:THE_END
pause
posted on 2012-10-11 10:25  凌度  阅读(750)  评论(0编辑  收藏  举报