我使用 ImageMagick 对图像执行命令行操作,例如调整大小、降低质量等。
但是,我遇到了这个脚本的问题:
SETLOCAL ENABLEDELAYEDEXPANSION
@echo off
REM Make the Modified folder, to store resized images.
if not exist %CD%\Mod MKDIR %CD%\Mod
REM loop through all files in working directory with extensions of .bin
for /r %CD% %%G in (*.bin) do (
set FILENAME=%%~nG
echo !FILENAME!.bin conversion beginning...
echo Beginning conversions...
echo Convert to TIF
REM rename the bin file with a .TIF extension.
copy !FILENAME!.bin !FILENAME!.tif
echo resizing image....
REM convert the tif and resize it to 25%. This is where it reduces to almost nothing!
convert !FILENAME!.tif -resize 25% !FILENAME!.tif
echo Renaming file...
REM rename file to say it had been modified
ren !FILENAME!.tif !FILENAME!-mod.tif
echo Copying file...
REM copy the file to the Mod directory.
copy /y !FILENAME!-mod.tif %CD%\Mod
echo Cleaning up...
REM cleanup.
DEL !FILENAME!-mod.tif
echo Moving on to next file...
)
如果我从命令行运行调整图像大小的命令,它可以正常工作,并将图像减小到估计的大小。在脚本中,它缩小到非常小的尺寸,我们谈论的是从大约 2500x5000 降低到 25x25,或类似的东西。这真的很奇怪,因为我正在执行完全相同的语句,尽管方式不同。
我最初认为是 for 循环在起作用,但我逐步通过它,边走边暂停,并随着那一次执行调整大小,确保它不是 for 循环不断将图像大小调整 25% 直到它是太小了,不能走得更远。
为什么它减少这么小,我该如何解决?
编辑 1:它转换 bin 文件的原因是因为所有 BIN 文件实际上都是 TIF 文件,无论出于何种原因,这些文件都已使用 bin 扩展名重命名。它们实际上是图像。