Ree*_*ams 16 windows shell jpeg batch-file image-resizing
我正在寻找一些帮助来编写一个批处理脚本来调整一堆.jpg图像.
我对批处理脚本没有多少经验.但是这个任务将在Windows机器上执行,所以我认为批处理脚本可能是一个很好的方法.
我总是有兴趣听取其他想法和方法,或者意识到我没有想到的元素.
下面我列出了脚本的基本步骤/需求:
1) The images are located in a folder & are all(or should be) 500 x
500.
2) I need copy & past the images to a new folder, where they will be
resized to 250 x 250.
3) I then need to repeat step 2 but this time resize to 125 x 125.
Run Code Online (Sandbox Code Playgroud)
ken*_*orb 17
安装ImageMagick for Windows后,可以使用magick
命令行工具,例如
magick.exe mogrify -resize 250x250 -path 250x250/ *.png *.jpg
magick.exe mogrify -resize 125x125 -path 125x125/ *.png *.jpg
Run Code Online (Sandbox Code Playgroud)
注意:确保您的magick.exe
命令在您的PATH
系统变量中,并且您指向现有或创建目标文件夹(例如,mkdir 250x250/ 125x125/
在上面的情况下).
对于Linux/Ubuntu,请参阅:如何通过命令行轻松调整图像大小?
Ric*_*aña 16
npo*_*aka 10
您可以检查scale.bat
哪些可以调整图像大小而无需安装其他软件 - 它只使用Windows内置功能:
@echo off
set "source_folder=c:\images"
set "result_folder_1=c:\res1"
set "result_folder_2=c:\res2"
for %%a in ("%source_folder%\*jpg") do (
call scale.bat -source "%%~fa" -target "%result_folder_1%\%%~nxa" -max-height 250 -max-width 250 -keep-ratio no -force yes
)
for %%a in ("%source_folder%\*jpg") do (
call scale.bat -source "%%~fa" -target "%result_folder_2%\%%~nxa" -max-height 125 -max-width 125 -keep-ratio no -force yes
)
Run Code Online (Sandbox Code Playgroud)
检查一下.
如果你想在命令行上专门做,也许你可以自动化它,批处理中没有特定的命令用于图像处理.您可以使用JScript或其他语言对某些内容进行编码并从命令行运行它,但为什么在有成熟工具可用于此任务时呢?
我推荐ImageMagick.
获取可移植的Windows二进制文件,然后您可以使用magick.exe轻松地执行您想要的操作.例如,要将文件夹1中的所有png图像调整大小(减半)到文件夹2:
@echo off
if not exist 2 md 2
for %%a in (1\*.png) do "path\to\magick.exe" -resize 50x50% "1\%~nxa" "2\%~nxa"
Run Code Online (Sandbox Code Playgroud)