Skip to content

Instantly share code, notes, and snippets.

@TobiasPott
Last active July 30, 2020 08:49
Show Gist options
  • Save TobiasPott/43e36a000028c70cc67d8adbd85ff4ec to your computer and use it in GitHub Desktop.
Save TobiasPott/43e36a000028c70cc67d8adbd85ff4ec to your computer and use it in GitHub Desktop.
echo off
if [%1]==[] (
echo No path given as parameter
exit /b
) else (
set basePath=%1
)
REM Optional second parameter to point to ImageMagick executable
if [%2]==[] (
set imPath="C:\Program Files\ImageMagick\7.0.10-Q16-HDRI\magick.exe"
) else (
set imPath=%2
)
set folders=(*.tif, *.tiff, *.png, *.jpg, *.jpeg)
REM for %%f in (%folderPathTif%, %folderPathPng%, %folderPathJpg%) do (
for /R %basePath% %%f in %folders% do (
setlocal enabledelayedexpansion
set ext=%%~xf
set name=%%~nf
REM ! indicated delayed expansion which causes the variable to contain the correct extension value
if "!ext!"==".png" (
echo PNG !name!
%imPath% "%%f" -resize 50%% "%%f"
)
if "!ext!"==".jpg" (
echo JPG !name!
%imPath% "%%f" -resize 50%% "%%f"
)
if "!ext!"==".jpeg" (
echo JPG !name!
%imPath% "%%f" -resize 50%% "%%f"
)
if "!ext!"==".tif" (
echo TIFF !name!
%imPath% "%%f" -channel RGBA -separate -resize 50%% -resize 1024x1024^> -combine -compress lzw "%%f"
)
if "!ext!"==".tiff" (
echo TIFF !name!
%imPath% "%%f" -channel RGBA -separate -resize 50%% -resize 1024x1024^> -combine -compress lzw "%%f"
)
endlocal
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment