Search code examples
windowsbatch-fileimagemagickmogrify

Why does mogrify resize a PNG to a width of 50 pixels instead of 50% as specified in batch file?


With some help I've made this code:

mkdir SDtemp
copy *@2x*.png SDtemp
mogrify -format png -resize 50% SDtemp/*@2x*.png
pushd SDtemp

setlocal enableDelayedExpansion
for %%a in (*.png) do (
    set "filename=%%~nxa"
    set "purged_filename=!filename:@2x=!"
    ren %%~nxa !purged_filename!
)

endlocal
move *.png ..
popd
rmdir /s /q SDtemp

I think, my problem is on this line:

   mogrify -format png -resize 50% SDtemp/*@2x*.png

It doesn't resize correctly. An image that was 320x320 is now 50x50 and another image that was 600x140 is 50x12, really weird.

I want it to resize like this: 320x320 -> 160x160

Edit: I found the problem, I had to write %% because % is a special character.


Solution

  • Use double percent-signs:

    mogrify -format png -resize 50%% SDtemp/*@2x*.png