我和另一個傢伙正試圖共同編寫一個批處理文件,該文件將使用ImageMagick命令執行各種圖像操作。ImageMagick批處理文件停止工作
我們得到它的工作,我決定將它移動到硬盤上的另一個位置。 突然之間腳本不再工作了。
它創建文件夾「修改」,但不執行圖像轉換。 我可以從命令提示符執行轉換命令,但不能使用腳本。
我換了電腦,過了一段時間它又發生了!
我不知道發生了什麼。 我曾嘗試:
- 將其移回原來的位置
- 重新啓動計算機,由羅伊勸在IT人羣
- 重新安裝ImageMagick的
- 祈求IT神(誰可能有許多名字:蓋茨,工作,Thorvald,空等)
沒有任何成就! 請幫助我的任何有用的提示!
環境:
64位Windows 7
的ImageMagick 6.8.0-6 Q16
的批處理文件內容如下:
@echo off
:: Drag and drop a folder of images on the BAT-file.
:: A
Setlocal enabledelayedexpansion
:: Removes the last slash if given in argument %1
Set "Dir=%~1"
IF "%DIR:~-1%" EQU "\" (Set "Dir=%DIR:~0,-1%")
:: Create the output folder if don't exist
MKDIR ".\modified" 2>NUL
:: Set maximium image height
SET /A "newHeight=780"
:: Set portrate extent width
SET /A "portrateWidth=585"
:: Read all the png and jpg images from the directory
FOR %%f IN ("%dir%\*.tif" "%dir%\*.jpg") DO (
:: Set the variable width to the image width
For /F %%# in ('identify -ping -format "%%[fx:w]" "%%f"') Do (SET /A "width=%%#")
:: Set the variable height to the image height
For /F %%# in ('identify -ping -format "%%[fx:h]" "%%f"') Do (SET /A "height=%%#")
:: Check if the photo is portrate or landscape and run the relavant code
IF !height! LSS !width! (
convert "%%f" -trim -resize x!newHeight! "modified\%%~nf.jpg"
) ELSE (
:: Only resize if height is over 780
IF !height! LSS !newHeight! (
:: Calculation for portrate extent width
SET /A "newWidth=!height! * 3/4"
convert "%%f" -trim -resize x!height! -background blue -gravity center -extent !newWidth!x!height! "modified\%%~nf.jpg"
) ELSE (
convert "%%f" -trim -resize x!newHeight! -background blue -gravity center -extent !portrateWidth!x!newHeight! "modified\%%~nf.jpg"
)
)
)
PAUSE&EXIT
感謝您的信息,但它並沒有解決我的問題。 完全相同的BAT文件正在我擁有的第三臺計算機上工作,並且也在我的共同編寫者計算機上工作。它沒有任何明顯的理由已停止在兩臺計算機上工作。 – MrDark
如果相同的腳本在其他PC上工作,那麼問題似乎是imagemacgik,請確保您在PATH中具有所需的imagemagick路徑,在cmd中鍵入PATH並搜索imagemagick目錄。哦,如果你想放棄這個問題,使用imagemagick目錄裏面的腳本。 – ElektroStudios
我已經更新了我的答案的代碼,請看第一條命令。 – ElektroStudios