slyfox1186

Best ImageMagick script to reduce JPG file sizes with near lossless quality

Dec 4th, 2020 (edited)
697
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. REM THIS IS ONE OF THE BEST IMAGEMAGICK SCRIPTS TO SHRINK ANY SIZED JPG FILES WITH NEAR LOSSLESS QUALITY
  2. REM I'VE SEEN 50 MB IMAGES BECOME 3-4 MB.... AND I HAVE TO USE A SPECIAL PROGRAM TO SEE THE ACTUAL QUALITY DIFFERENCES THE RESULTS ARE SO IMPRESSIVE
  3.  
  4. REM IF YOU WANT A SCRIPT MADE FOR VERY LARGE JPG FILES SEE MY OTHER SCRIPT ( https://pastebin.com/j30HJAx3 )
  5.  
  6. REM INSTRUCTIONS!!
  7. REM CREATE A BATCH SCRIPT AND PLACE IT IN A TEST FOLDER FULL OF JPG FILES TO PROCESS
  8. REM MAKE SURE YOU HAVE THE LATEST VERSION OF IMAGEMAGICK INSTALLED FOR WINDOWS
  9. REM ( https://imagemagick.org/script/download.php )
  10. REM YOU MUST DOWNLOAD ONE OF THE DLL VERSIONS THATS NAME ENDS WITH "HDRI-x64-dll.exe"
  11. REM YOU MUST CHOOSE THE LEGACY PROGRAMS OPTION WHEN INSTALLING IMAGEMAGICK OR WINDOWS WONT RECOGNIZE THE "CONVERT" COMMAND
  12. REM YOU ALSO NEED TO PLACE THE ROOT INSTALL DIRECTORY ( C:\Program Files\ImageMagick-blah-blah ) IN YOUR WINDOWS ENVIRONMENT PATH
  13. REM OR POINT THE FULL PATH OF [ C:\Program Files\ImageMagick-blah-blah\mogrify.exe ] IN PLACE OF THE MOGRIFY COMMAND IN THE SCRIPT BELOW
  14.  
  15. REM IMPORTANT!!
  16. REM THE NEW OPTIMIZED FILES WILL BE FOUND IN A SUBFOLDER NAMED "Output"
  17.  
  18. REM BEGIN SCRIPT!!
  19.  
  20. @ECHO OFF
  21. SETLOCAL
  22. COLOR 0A
  23. TITLE USE IMAGEMAGICK TO GREATLY REDUCE ALL JPG FILE SIZES WITH NEAR LOSSLESS QUALITY
  24.  
  25. PUSHD "%~dp0"
  26.  
  27. IF NOT EXIST "Output" ( MKDIR "Output" )
  28.  
  29. SETLOCAL ENABLEDELAYEDEXPANSION
  30. FOR %%G IN (*.jpg) DO (
  31. FOR /F "TOKENS=3" %%I IN ('MAGICK identify "%%G"') DO (
  32.     SET /A CNT+=1
  33.     SET "file!CNT!=%%~nxG"
  34.     ECHO=
  35.     CALL ECHO [!CNT!] Converting Image: %%file!CNT!%%
  36.     ECHO=
  37.     MOGRIFY -monitor -path Output/ -filter Triangle -define filter:support=2 -thumbnail "%%I" -unsharp 0.25x0.08+8.3+0.045 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude-chunk=all -interlace none -colorspace sRGB -format jpg "%%G"
  38.     ECHO=
  39.     REM FINISH THE SCRIPT IF ALL FILES HAVE BEEN PROCESSED
  40.     IF "%%G"=="" ( ENDLOCAL )
  41.     )
  42. )
  43.  
  44. REM OPEN EXPLORER TO THE OUTPUT FOLDER
  45. START "" /MAX explorer.exe "%CD%\Output"
  46. EXIT
RAW Paste Data