Announcement

Collapse
No announcement yet.

Batch reszing images

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Batch reszing images

    Hi,

    this script could be placed somewhere (BatchResize.cmd).
    Code:
    @echo off
    rem *******************
    rem * BatchResize.cmd *
    rem *******************
    rem Drag and drop a folder or folder structure to this script and IrfanView will
    rem resize all pictures of the given file type to the given pixel size. Smaller
    rem pictures will not be touched.
    rem Also the jpeg quality could be set.
    cls
    setlocal
    
    
    rem Check parameter
    if "%~1"=="" goto noparam
    
    rem Path to Irfan view
    if /i "%PROCESSOR_ARCHITECTURE%" equ "AMD64" (
     rem Path to IrfanView on x64 Windows
     set iview="%ProgramFiles(x86)%\IrfanView\i_view32.exe"
    ) else (
     rem Path to IrfanView on x86 Windows
     set iview="%ProgramFiles%\IrfanView\i_view32.exe"
    )
    if not exist %iview% goto noIview
    
    
    rem File type
    set filetype=*.jpg
    
    rem Width
    set width=1000
    
    rem JPEG quality
    set quality=75
    
    rem temporaery file
    set tmpfile="%temp%\imageinfo.txt"
    
    echo Converting...
    for /r "%~1" %%a in (%filetype%) do call :Resize "%%a"
    
    echo.
    echo Finished converting.
    
    rem After finishing go to the end
    goto end
    
    :noparam
    echo No path given!
    goto end
    
    
    rem IrfanView could not be found.
    :noiview
    echo IrfanView not found in the given path:
    echo   %iview%
    goto end
    
    :resize
    echo Checking file "%~1"
    start /wait "IrfanView" %iview% %1 /info=%tmpfile%
    set imagewidth=0
    for /f "tokens=4 delims= " %%b in ('type %tmpfile% ^| find /i "image dimensions"') do set /a imagewidth=%%b
    if "%imagewidth%" gtr "%width%" (
     echo Resizing file "%~1"
     start /wait "IView" %iview% "%~1" /resize_long=%width% /aspectratio /resample /jpgq=%quality% /convert="%~1"
    )
    goto :eof
    
    rem End of the script
    :end
    if exist %tmpfile% del %tmpfile%
    pause
    endlocal
    Some parameters may be modified:
    The searched file type is JPEG by default:
    Code:
    set filetype=*.jpg
    Since JPEG files can be saved with a special quality parameter this could also be changed:
    Code:
    set quality=75
    Change all files bigger than 1000 pixel width and set the new long side to this value:
    Code:
    set width=1000
    Be careful, this script is destructive and will overwrite pictures (take file xyz.jpg, resize it and save it back as xyz.jpg)!

    Have fun
    Nils
    Last edited by derniwi; 24.10.2011, 06:16 PM.

    #2
    Hey
    Maybe someone can offer little help

    I modified this script for 2 runs - one for aspect with widht (as original), and second to generate thumbs 56x75 px
    I also tried to rename output files
    Script works with image, but no output appears

    Code:
    @echo off
    rem *******************
    rem * BatchResize.cmd *
    rem *******************
    rem Drag and drop a folder or folder structure to this script and IrfanView will
    rem resize all pictures of the given file type to the given pixel size. Smaller
    rem pictures will not be touched.
    rem Also the jpeg quality could be set.
    cls
    setlocal
    
    
    rem Check parameter
    if "%~1"=="" goto noparam
    
    rem Path to Irfan view
     rem Path to IrfanView on x86 Windows
     set iview="%ProgramFiles%\IrfanView\i_view64.exe"         rem<--- this was also change
    if not exist %iview% goto noIview
    
    
    rem File type
    set filetype=*.jpg
    
    rem Width
    set width=1024
    
    rem JPEG quality
    set quality=80
    
    rem temporaery file
    set tmpfile="%temp%\imageinfo.txt"
    
    echo Converting...
    for /r "%~1" %%a in (%filetype%) do call :Resize "%%a"
    
    echo.
    echo Finished converting.
    
    rem Second run for mini                           rem added this
    
    set width=75
    set height=56
    
    echo Convert mini
    for /r "%~1" %%a in (%filetype%) do call :Resize2 "%%a"
    
    rem After finishing go to the end
    goto end
    
    :noparam
    echo No path given!
    goto end
    
    
    rem IrfanView could not be found.
    :noiview
    echo IrfanView not found in the given path:
    echo   %iview%
    goto end
    
    :resize
    echo Checking file "%~1"
    start /wait "IrfanView" %iview% %1 /info=%tmpfile%
    set imagewidth=0
    for /f "tokens=4 delims= " %%b in ('type %tmpfile% ^| find /i "image dimensions"') do set /a imagewidth=%%b
    if "%imagewidth%" gtr "%width%" (
     echo Resizing file "%~1"
     start /wait "IView" %iview% "%~1" rename_pattern=## /resize_long=%width% /aspectratio /resample /jpgq=%quality% /convert="%~1"         rem pattern here and below
    )
    goto :eof
    
    :resize2
    echo Checking file "%~1"
    start /wait "IrfanView" %iview% %1 /info=%tmpfile%
    set imagewidth=0
    for /f "tokens=4 delims= " %%b in ('type %tmpfile% ^| find /i "image dimensions"') do set /a imagewidth=%%b
    if "%imagewidth%" gtr "%width%" (
     echo Resizing file "%~1"
     start /wait "IView" %iview% "%~1" /rename_pattern=m## /resize_width=%width% /resize_height=%height% /resample /jpgq=%quality% /convert="%~1"
    )
    goto :eof
    
    rem End of the script
    :end
    if exist %tmpfile% del %tmpfile%
    pause
    endlocal

    Comment

    Working...
    X