I use ImageMagick to perform command line operations on images, such as resizing, reducing quality, etc.
However, I’ve run into a problem with this script:
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...
)
If I run the command that resizes the image from the command line, it works fine, and reduces the image to the estimated size. In the script, it reduces to extraordinarily small dimensions, we’re talking about going from around 2500×5000 down to 25×25, or something similar. It’s really strange, since I am executing the exact same statement, albeit in a different manner.
I had originally assumed that it was the for loop acting up, but I stepped through it, pausing as I went, and it resized with that one execution, ensuring that it was not the for loop constantly resizing the image by 25% until it was too small to go any further.
Why is it reducing so small, and how can I fix it?
Edit 1: The reason it’s converting bin files is because all of the BIN files are actually TIF files that have been renamed with the bin extension for whatever reason. They are, in fact, images.
I would guess you need to escape the % with another % so 25% becomes 25%%