Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
can someone help me to add proportional resize code to this script: for example 1000xproportional and resize it again with white background if the image is not 1000x1000
like yc:white +swap -gravity center -composite \
@ECHO OFF
set resizeSize=1000x1000
set dirCnt=0
set tmpCnt=0
set convert_exe=C:\Program Files\ImageMagick-6.8.0-Q16\convert.exe
set foldername=%1
REM remove double quote from string
set distfolder=%foldername%"\1000x1000"
set distfolder=%distfolder:""=%
REM =(1)============< CHECK PATH MAGIC >============================================
IF NOT EXIST "%convert_exe%" (
echo ImageMagick path is incorrect. You need to set it up in batch file!
echo Current value: %convert_exe%
pause
exit 4
)
REM =(2)============< COUNT JPG files >===================================================
for /F "usebackq delims=" %%i in (`dir /a:-d /b %foldername%\*.jpg`) do set /a dirCnt+=1
IF (%dirCnt%) EQU (0) (
call set foldername=%%~dp1
for /F "usebackq delims=" %%i in (`dir /a:-d /b %%foldername%%\*.jpg`) do set /a dirCnt+=1
)
IF (%dirCnt%) EQU (0) (
echo JPG files not found in folder "%foldername%". Exiting.
pause
EXIT 1
)
echo Found %dirCnt% JPG files in folder %foldername%.
REM =(3)===============< MAKE WEB DIR >===============================
set tmpCnt=0
for /F "usebackq delims=" %%i in (`dir /B /A:D %foldername%`) do (
if %%i EQU web600 set /a tmpCnt+=1
)
IF (%tmpCnt%) EQU (0) md %foldername%\1000x1000
REM ==============================================================
set tmpCnt=0
for /F "usebackq delims=" %%i in (`dir /B /A:D %foldername%`) do (
if %%i EQU web600 set /a tmpCnt+=1
)
IF (%tmpCnt%) EQU (0) (
echo Error! Can't create folder "%foldername%\1000x1000".
pause
EXIT 2
)
REM ==============================================================
echo Resizing JPG files in %foldername%:
chdir /D %foldername%
set tmpCnt=0
for /F "usebackq delims=" %%i in (`dir /a:-d /b %foldername%\*.jpg`) do (
set /a tmpCnt+=1
call echo Proceed file %%tmpCnt%% from %%dirCnt%%: "%%i"
"%convert_exe%" "%%i" -interpolate bicubic -filter lagrange -set option:filter:support 2.0 -set option:filter:win-support 12 -set option:filter:lobes 8 -resize %resizeSize% -quality 95 ".\1000x1000\%%i"
)
echo ""
echo Resizing is done, check folder web for results!
echo ""
pause
Thank you for the reply fred's actually i found a script in your library that do 80% of what i want ASPECTPAD, i want the script to detect how many picture in the folder and resize them and send them to a new folder called let's say 1000x1000 but in this process their is a catch, i want to fix the vertical pictures and give them a white background with fix dimension, i was able to do the auto resize and send them to a new folder but i need ASPECTPAD to be linked also to the process
What is your IM version and platform? What is the fixed size you want for the portrait images? What do you want to happen to the landscape images? Are you resizing only if the image is too large, or are you resizing only if the image is too small, or are you resizing all images.
Please provide and outline of the steps you want to happen.
i have pictures size coming to me 5000x5000 i want to resize them to 2000x2000 but some of those images that comes they are not promotional let’s say 5000x3000 I want the script to detect those pictures and resize them proportionally to 2000xpropotionaly and after that resize the image to 2000x2000 and add extra white background to the empty space ( like your example) when it's done i want them to get moved to a folder called 2000x2000
@ECHO OFF
set resizeSize=1000x1000
set dirCnt=0
set tmpCnt=0
set convert_exe=C:\Program Files\ImageMagick-6.8.0-Q16\convert.exe
set foldername=%1
REM remove double quote from string
set distfolder=%foldername%"\1000x1000"
set distfolder=%distfolder:""=%
REM =(1)============< CHECK PATH MAGIC >============================================
IF NOT EXIST "%convert_exe%" (
echo ImageMagick path is incorrect. You need to set it up in batch file!
echo Current value: %convert_exe%
pause
exit 4
)
REM =(2)============< COUNT JPG files >===================================================
for /F "usebackq delims=" %%i in (`dir /a:-d /b %foldername%\*.jpg`) do set /a dirCnt+=1
IF (%dirCnt%) EQU (0) (
call set foldername=%%~dp1
for /F "usebackq delims=" %%i in (`dir /a:-d /b %%foldername%%\*.jpg`) do set /a dirCnt+=1
)
IF (%dirCnt%) EQU (0) (
echo JPG files not found in folder "%foldername%". Exiting.
pause
EXIT 1
)
echo Found %dirCnt% JPG files in folder %foldername%.
REM =(3)===============< MAKE WEB DIR >===============================
set tmpCnt=0
for /F "usebackq delims=" %%i in (`dir /B /A:D %foldername%`) do (
if %%i EQU web600 set /a tmpCnt+=1
)
IF (%tmpCnt%) EQU (0) md %foldername%\1000x1000
REM ==============================================================
set tmpCnt=0
for /F "usebackq delims=" %%i in (`dir /B /A:D %foldername%`) do (
if %%i EQU web600 set /a tmpCnt+=1
)
IF (%tmpCnt%) EQU (0) (
echo Error! Can't create folder "%foldername%\1000x1000".
pause
EXIT 2
)
REM ==============================================================
echo Resizing JPG files in %foldername%:
chdir /D %foldername%
set tmpCnt=0
for /F "usebackq delims=" %%i in (`dir /a:-d /b %foldername%\*.jpg`) do (
set /a tmpCnt+=1
call echo Proceed file %%tmpCnt%% from %%dirCnt%%: "%%i"
"%convert_exe%" "%%i" -interpolate bicubic -filter lagrange -set option:filter:support 2.0 -set option:filter:win-support 12 -set option:filter:lobes 8 -resize %resizeSize% -quality 95 ".\1000x1000\%%i"
)
echo ""
echo Resizing is done, check folder web for results!
echo ""
pause
Sorry, I do not know Windows batch file programming. Test my simple command on individual images and see if that is what you want. Perhaps one of the Windows users may be able to help you integrate it, once you reply that it is what you want to happen.