web-dev-qa-db-ja.com

画像のサイズを変更するバッチスクリプト

大量の.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.
14
Reed Williams

Windows用Image Resizer を使用します。

enter image description here

enter image description here

Windows用ImageMagick をインストールしたら、 magickコマンドラインツール を使用できます。

magick.exe mogrify -resize 250x250 -path 250x250/ *.png *.jpg
magick.exe mogrify -resize 125x125 -path 125x125/ *.png *.jpg

注:magick.exeコマンドはPATHシステム変数にあり、既存のフォルダーまたは作成されたフォルダー(たとえば、mkdir 250x250/ 125x125/上記の場合)。

Linux/Ubuntuの場合は、以下を参照してください。 コマンドラインを使用して画像を簡単にサイズ変更するには?

16
kenorb

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
)

this も確認してください。

7
npocmaka

おそらくそれを自動化できるように、コマンドラインで具体的に実行したい場合、Batchには画像操作用に作成された特定のコマンドはありません。 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"
6
soja