teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

正常に動作確認済み

2018/03/27 03:18

投稿

ZZ-TOP
ZZ-TOP

スコア36

title CHANGED
File without changes
body CHANGED
@@ -99,4 +99,27 @@
99
99
  convert -resize 900x %%f %%~nf_resized.png
100
100
  )
101
101
  )
102
+ ```
103
+
104
+ ```バッチファイル
105
+ setlocal enabledelayedexpansion
106
+ REM ↑このコマンドは必要!
107
+
108
+ for %%f in (*.png) do (
109
+ REM 画像の縦幅を取得
110
+ REM "%%h"でくくる、「'」でくくると文字扱いになる=条件式が機能しない
111
+ for /f "usebackq tokens=*" %%i in (`identify -format "%%h" %%f`) do @set HEIGHT=%%i
112
+
113
+ REM 画像の横幅を取得
114
+ for /f "usebackq tokens=*" %%i in (`identify -format "%%w" %%f`) do @set WIDTH=%%i
115
+
116
+
117
+ if !HEIGHT! GEQ !WIDTH! (
118
+ REM 縦幅 >= 横幅
119
+ convert -resize x900 %%f %%~nf_resized.png
120
+ ) else (
121
+ REM 縦幅 < 横幅
122
+ convert -resize 900x %%f %%~nf_resized.png
123
+ )
124
+ )
102
125
  ```

3

2回目のアドバイス

2018/03/27 03:18

投稿

ZZ-TOP
ZZ-TOP

スコア36

title CHANGED
File without changes
body CHANGED
@@ -80,4 +80,23 @@
80
80
  convert -resize 900x %%f %%~nf_resized.png
81
81
  )
82
82
  )
83
+ ```
84
+
85
+ ```バッチファイル
86
+ for %%f in (*.png) do (
87
+ REM 画像の縦幅を取得
88
+ for /f "usebackq tokens=*" %%i in (`identify -format "%%h" %%f`) do @set HEIGHT=%%i
89
+
90
+ REM 画像の横幅を取得
91
+ for /f "usebackq tokens=*" %%i in (`identify -format "%%w" %%f`) do @set WIDTH=%%i
92
+
93
+
94
+ if !HEIGHT! GEQ !WIDTH! (
95
+ REM 縦幅 >= 横幅
96
+ convert -resize x900 %%f %%~nf_resized.png
97
+ ) else (
98
+ REM 縦幅 < 横幅
99
+ convert -resize 900x %%f %%~nf_resized.png
100
+ )
101
+ )
83
102
  ```

2

アドバイスにより追加

2018/03/27 02:18

投稿

ZZ-TOP
ZZ-TOP

スコア36

title CHANGED
File without changes
body CHANGED
@@ -58,4 +58,26 @@
58
58
  convert -resize 900x %%f %%~nf_resized.jpg
59
59
  )
60
60
  )
61
+ ```
62
+
63
+ ```バッチファイル
64
+ for %%f in (*.png) do (
65
+ REM 画像の縦幅を取得
66
+ for /f "usebackq tokens=*" %%i in (`identify -format '%%h' %%f`) do @set HEIGHT=%%i
67
+
68
+ REM 画像の横幅を取得
69
+ for /f "usebackq tokens=*" %%i in (`identify -format '%%w' %%f`) do @set WIDTH=%%i
70
+
71
+ REM アドバイスにより追加
72
+ set HEIGHT=!HEIGHT:'=!
73
+ set WIDTH=!WIDTH:'=!
74
+
75
+ if !HEIGHT! GEQ !WIDTH! (
76
+ REM 縦幅 >= 横幅
77
+ convert -resize x900 %%f %%~nf_resized.png
78
+ ) else (
79
+ REM 縦幅 < 横幅
80
+ convert -resize 900x %%f %%~nf_resized.png
81
+ )
82
+ )
61
83
  ```

1

タイプミスの修正「縦幅→縦」

2018/03/27 02:03

投稿

ZZ-TOP
ZZ-TOP

スコア36

title CHANGED
File without changes
body CHANGED
@@ -51,10 +51,10 @@
51
51
  for /f "usebackq tokens=*" %%j in (`identify -format '%%w %%h'`) do @set WIDTH=%%w
52
52
 
53
53
  if !HEIGHT! GEQ !WIDTH! (
54
- REM 縦 >= 横幅
54
+ REM 縦 >= 横幅
55
55
  convert -resize x900 %%f %%~nf_resized.jpg
56
56
  ) else (
57
- REM 縦 < 横幅
57
+ REM 縦 < 横幅
58
58
  convert -resize 900x %%f %%~nf_resized.jpg
59
59
  )
60
60
  )