Page 1 of 1

Resize p

Posted: 2016-10-31T07:35:51-07:00
by souwar
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 \

Image

Code: Select all

@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

Re: Resize p

Posted: 2016-10-31T09:53:39-07:00
by fmw42
Not sure what you are asking!

Have you seen the use of > and < in http://www.imagemagick.org/script/comma ... p#geometry. They will resize proportional if the image is either larger (>) or smaller (<) than the size specified.

Re: Resize p

Posted: 2016-10-31T10:19:24-07:00
by souwar
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

Re: Resize p

Posted: 2016-10-31T10:35:58-07:00
by fmw42
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.

Re: Resize p

Posted: 2016-10-31T11:40:13-07:00
by souwar
i sent you a pm

Re: Resize p

Posted: 2016-10-31T13:01:36-07:00
by fmw42
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
try in IM 6

Code: Select all

convert path2/yourimage -resize 2000x2000 -gravity center -background white -extent 2000x2000 path_to/2000x2000/yourresult
or in IM 7

Code: Select all

magick path2/yourimage -resize 2000x2000 -gravity center -background white -extent 2000x2000 path_to/2000x2000/yourresult
See http://www.imagemagick.org/Usage/thumbnails/#pad

Re: Resize p

Posted: 2016-10-31T16:05:48-07:00
by souwar
thank you sir, and sorry for the PM :), what would be the full code based on my code? i can still be able to use it?

Code: Select all

@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

Re: Resize p

Posted: 2016-10-31T16:55:05-07:00
by fmw42
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.

Re: Resize p

Posted: 2016-10-31T17:32:32-07:00
by souwar
thank you, do i need to open a new post for this mater