Announcement

Collapse
No announcement yet.

the ultimate tool for PNG compression optimisation

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

    the ultimate tool for PNG compression optimisation

    Hi folks. IrfanView does a good job saving png files, especially with the PNGout plugin. But for all of you who want to squeeze out the max of PNG compression, here is "the ultimate guide to PNG optimisation"

    I wrote a little batch script, that uses several different external PNG converters. They are all freeware and I want to collectively thank the authors for doing such a good job and sharing their work with us. When you run the batch file, you will see the names of the converters displayed and most converters also display the author's name, so that they get the credit they deserve.

    You use my batch file like this:
    pngopti [IMAGE] [-EXTREME]

    both parameters are optional. "Image" is the input image. Currently supported are: GIF, TIF(F), JP(E)G, BMP, PNM, TGA, PCX. If "image" is not specified, the batch script takes the clipboard content as input. The "-extreme" switch uses the most extreme parameters for the converters, so that they try every optimisation method, but it takes a lot longer and it's very rare that the output file is smaller than withouth the "-extreme" switch.
    The script first tells you how your png file is structured (chunks, etc.). Then it tells you how many unique colors are currently used. You can then choose a desired amount of colors if you wish (that's the only lossy part of the opimisation, but optional) ... comes in very handy if one wants ultimate compression ... Then you can choose which PNG chunks to delete and which to keep. And then the different converters are used. Each tool has its own individual strengths and therefore the order in which they are executed is crucial.

    Installation: You only have to extract the .zip file to any directory. But you also have to install ImageMagick (which is responsible for the optional color reduction) http://www.imagemagick.org/script/bi...es.php#windows
    Finally you have to edit the script in line 3, where you have write the paths that you choose for the batch script and ImageMagick. That's it.

    caveats:
    1) Normally long file names+paths are supported. But sometimes I get errors, when they are too long. There will be red text when that occurs. I still have to fix the script. If you want to make absolutely sure, keep filenames and paths rather short.
    2) when running the script, you are asked which chunks to delete and which to keep. Unfortunately some converters used subsequently in the script just delete all unnecessary chunks, so for the moment you will loose these chunks. One day I have to change that somehow ...


    So, I hope you have fun with it ...

    Obviously the usual conditions apply, i.e. you can do whatever you want with it. And I deny the usual stuff, i.e. any responsibility for anything, including fitness for a particular purpose, or any damages resulting from the use of the script, whether directly or indirectly, etc. bla bla And as I said, the external converters are freeware and not written by me. So here we go:

    Here is the package (script+optimizers):
    Attached Files
    Last edited by boarder's paradise; 06.12.2008, 04:21 AM.

    #2
    And here is the script:

    Code:
    @echo off
    setlocal enabledelayedexpansion
    PATH d:\appz\PNGopti;d:\appz\ImageMagick;%PATH%
    cls
    set currentcolors=0
    
    
    echo.
    cecho {white}------------------- INPUT FILE SIZE:{lime} %~z1 {white}-------------------{\n}
    
    if /i "%~x1" == ".png" (copy %1 "%~n1.convert.png" >nul) & goto :optimizenow
    cecho {\n}
    
    for %%b in (".gif" ".tiff" ".tif" ".bmp" ".pnm") Do if /i "%~x1" == %%b goto :convertwithoptipng
    for %%b in (".jpg" ".jpeg" ".tga" ".pcx") Do if /i "%~x1" == %%b goto :convertwithpngout
    
    
    cecho {blue}converting {aqua}clipboard image{blue} to .png with {silver}PNGout{blue} ...{\n\n}
    
    if "%2"=="-extreme" (set options=) else (set options=/s3)
    pngout "%~n1.convert.png" /i %options%
    
    cecho {\n}{white}--------------------------------------------------------------- {\n}
    
    if exist "%~n1.convert.png" goto :optimizenow
    
    cecho {red}{\n}input format unknown ... aborting program ... 
    pause >nul 
    goto :eof
    
    
    :: ########################
    :convertwithpngout
    cecho {blue}converting %~x1 to .png with PNGout ...{\n\n}
    cecho {white}------ PNGOUT ---- 9 Feb 2008 ---- by Ken Silverman ------{\n\n}{silver}
    
    if "%2"=="-extreme" (set options=) else (set options=/s3)
    
    pngout %1 "%~n1.convert.png" %options%
    
    call :comparesize %1 "%~n1.convert.png"
    cecho ============================================ {\n}
    goto :optimizenow
    
    
    :: ########################  
    :convertwithoptipng
    cecho {blue}{0x20} converting %~x1 to .png with optiPNG ...{\n\n}
    cecho {white}--------------------------------------------------------------- {\n\n}
    for /f "usebackq tokens=* delims=" %%a in (`optipng -fix -i0 -o1 -out "%~n1.convert.png" %1`) do call :colorresults "%%~a" gray 
    cecho {white}--------------------------------------------------------------- {\n}	
    
    
    :: ########################
    :optimizenow
    
    set hasbeenconverted=0
    for %%b in (".gif" ".tiff" ".tif" ".bmp" ".pnm" ".jpg" ".jpeg" ".tga" ".pcx") Do if /i "%~x1" == %%b set hasbeenconverted=1
    if %hasbeenconverted%==1 (call :results %1 "%~n1.convert.png" %1) ELSE (call :listchunks "%~n1.convert.png") 
    
    call :pngchk "%~n1.convert.png"
    
    cecho {blue}The image's current color depth provides: {aqua}%currentcolors% available colors{\n}
    cecho {blue}The image currently uses:
    for /f %%a in ('identify -format %%k %~n1.convert.png') do (cecho {aqua} %%~a unique colors{\n\n})
    
    cecho {blue}Enter desired amount of colors or hit enter to proceed.{\n}
    cecho (color reduction is optional and the only lossy part of{\n}
    cecho the optimization process...) : {aqua}
    set /p desiredcolors=
    if "%desiredcolors%"=="" (cecho no lossy color reduction) else (
        convert %~n1.convert.png +dither -colors %desiredcolors% %~n1.-colors.png
        for /f %%a in ('identify -format %%k %~n1.-colors.png') do (cecho {blue}{\n}The Image now uses:{aqua} %%~a unique colors)
    )
    cecho {\n}
    call :results "%~n1.convert.png" "%~n1.-colors.png" %1
    
    
    
    call :storefilesize "%~n1.-colors.png"
    
    
    for /f "usebackq tokens=* delims=" %%a in (`pngsplit -verbose "%~n1.-colors.png"`) do call :colorresults "%%~a" gray
    cecho {white}--------------------------------------------------------------- {\n\n}
    
    cecho {maroon}file consists of following chunks {red}(highlighted will be deleted):{\n\n}
    
    set xsig=(critical) file signature ("png")
    set xIHDR=(critical) image header (color type, etc.)
    set xPLTE=(critical) palette
    set xiDAT=(critical) actual image data
    set xIEND=(critical) emtpy end chunk
    set xtRNS=transparency
    set xgAMA=image gamma (brightness)
    set xcHRM=chromaticities (R,G,B + white point)
    set xsRGB=indicates sRGB color space + rendering intent
    set xiCCP=embedded ICC profile
    set xtEXt=text data
    set xzTXt=compressed text data
    set xiTXt=unicode text data (compr. or uncompr.)
    set xbKGD=background color
    set xpHYs=physical pixel dimensions
    set xsBIT=significant bits (original bit depth)
    set xsPLT=Suggested palette (instead of true colors)
    set xhIST=palette histogram (color frequency in palette)
    set xtIME=image's last-modification time
    
    
    for %%C in ("%~n1.-colors.png.00*") do (
    
      set chunk=%%~xC
      set chunk=!chunk:~1!
    
      set delchunk=0
      set ask=1
      for %%h in ("sig" "IHDR" "IDAT" "IEND") do if /i "!chunk!"==%%h set delchunk=0& set ask=0
      for %%i in ("hIST" "sPLT") Do if /i "!chunk!" == %%i set delchunk=1& set ask=0
      if /i "!chunk!" == "PLTE" (set ask=0& if !currentcolortype!==3 (set delchunk=0) ELSE (set delchunk=1))
      if /i "!chunk!" == "tRNS" (if not !currentcolortype!==3 (if not !currentcolortype!==0 (if !currentcolortype!==2 (set delchunk=1& set ask=0))))
    
      if !ask!==1 (
          cecho {maroon} del !chunk! ? 
          choice /N >nul
          if !ERRORLEVEL! == 1 (set delchunk=1) ELSE (set delchunk=0))
    
      if !delchunk!==1 (cecho {red}) else (cecho {maroon})
      if !ask!==0 cecho {0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}
    
      cecho {0x20} !chunk!{0x20}
      if "!chunk!"=="sig" (cecho {0x20})
      
      call :StrLength %%~zC
      set /a padding="%filesizelength% - !StrLength!"
      for /l %%X in (1,1,!padding!) do cecho {0x20}
    
      cecho %%~zC{0x20}
    
      
      if !delchunk!==1 (cecho {white}) else (cecho {gray})
      for %%k in (!chunk!) do cecho !x%%k! {\n}
      
      if !delchunk!==1 del "%%C"
    )
    
    copy /b "%~n1.-colors.png.00*" "%~n1.delchnk.png" >nul
    del "%~n1.-colors.png.00*"
    
    
    call :results "%~n1.-colors.png" "%~n1.delchnk.png" %1
    call :pngchk "%~n1.delchnk.png"
    
    
    cecho {fuchisa}
    cecho --- ImageMagick --- version 6.4.6-8-Q16 --- {\n\n}
    convert -verbose "%~n1.delchnk.png" "%~n1.opti000.png"
    :: ##################################################
    call :results "%~n1.delchnk.png" "%~n1.opti000.png" %1
    
    
    cecho {blue}
    echo --- pngrewrite -- version 1.2.1  - 8 Feb 2003
    echo.
    pngrewrite "%~n1.opti000.png" "%~n1.opti001.png"
    :: ############################################
    call :results "%~n1.opti000.png" "%~n1.opti001.png" %1
    
    
    cecho {teal}
    COPY "%~n1.opti001.png" "%~n1.opti002.png" >nul
    if "%2"=="-extreme" (set options=) else (set options=-o1)
    optipng -fix -i0 %options% "%~n1.opti002.png"
    :: ########################################
    call :results "%~n1.opti001.png" "%~n1.opti002.png" %1
    
    
    cecho {red}
    if "%2"=="-extreme" (set options=-brute) else (set options=)
    pngcrush -fix -reduce -m 0 %options% "%~n1.opti002.png" "%~n1.opti003.png"
    :: -rem alla removes all known ancillary chunks except for tRNS
    :: ##############################################################################
    call :results "%~n1.opti002.png" "%~n1.opti003.png" %1
    
    
    cecho {olive}
    echo PNGOUT --- 9 Feb 2008 --- by Ken Silverman (http://advsys.net/ken)
    echo.
    pngout "%~n1.opti003.png" "%~n1.opti004.png" /v
    :: ##########################################
    call :results "%~n1.opti003.png" "%~n1.opti004.png" %1
    
    
    cecho {teal}
    copy "%~n1.opti004.png" "%~n1.opti005.png" >nul
    if "%2"=="-extreme" (set options=-zc1-9 -zm1-9 -zs0-3 -f0-5) else (set options=)
    optipng -v -fix -i0 %options% "%~n1.opti005.png"
    :: ###########################################
    call :results "%~n1.opti004.png" "%~n1.opti005.png" %1
    
    
    cecho {fuchisa}
    COPY "%~n1.opti005.png" "%~n1.opti006.png" >nul
    echo. & advpng -V & echo.
    advpng -z -4 "%~n1.opti006.png"
    :: ##########################
    call :results "%~n1.opti005.png" "%~n1.opti006.png" %1
    
    
    cecho {purple}
    COPY "%~n1.opti006.png" "%~n1.opti007.png" >nul
    deflopt "%~n1.opti007.png"
    :: #####################
    call :results "%~n1.opti006.png" "%~n1.opti007.png" %1
    
    
    for /f "usebackq tokens=* delims=" %%a in (`png-fix-IDAT-windowsize -verbose "%~n1.opti007.png"`) do call :colorresults "%%~a" gray
    ::                                          #################################################
    call :results "%~n1.opti007.png" "%~n1.opti007-fixed.png" %1
    ren "%~n1.opti007-fixed.png" "%~n1.optifix.png"
    call :pngchk "%~n1.optifix.png"
    
    cecho {silver} ...optimization complete{0x21}{\n\n\n}
    
    
    set app1="input file     "
    set app2="PNG conversion "
    set app3="color reduction"
    set app4="chunk deletion "
    set app5="ImageMagick    "
    set app6="pngrewrite     "
    set app7="optipng        "
    set app8="pngcrush       "
    set app9="pngout         "
    set app10="optipng        "
    set app11="advpng         "
    set app12="deflopt        "
    set app13="png-fix        "
    
    set comparewith=%~z1
    set appcounter=0
    
    for %%a in ("%~nx1" "linefeed" "%~n1.convert.png" "%~n1.-colors.png" "%~n1.delchnk.png" "%~n1.opti000.png" "%~n1.opti001.png" "%~n1.opti002.png" "%~n1.opti003.png" "%~n1.opti004.png" "%~n1.opti005.png" "%~n1.opti006.png" "%~n1.opti007.png" "%~n1.optifix.png") do if %%a=="linefeed" (cecho {\n}) else (
       set /a appcounter += 1
       call :dellist %%a,!comparewith!,!appcounter!,%~z1
    )
    									
    
    call :calcfinalratio %1 "%~n1.optifix.png"
    
    cecho {white}{\n\n}Delete temporary files ? {0x20} 
    choice /N >nul
    if !ERRORLEVEL! == 1 (
         for %%a in ("%~n1.convert.png" "%~n1.-colors.png" "%~n1.delchnk.png" "%~n1.opti000.png" "%~n1.opti001.png" "%~n1.opti002.png" "%~n1.opti003.png" "%~n1.opti004.png" "%~n1.opti005.png" "%~n1.opti006.png" "%~n1.opti007.png") do del %%a
    
         cecho {red}...deleted{0x21}{\n\n}{gray}Renaming input and output file ...
         if "%~x1"==".png" ren "%~nx1" "%~nx1.old.png"
         if not exist "%~n1.png" ren "%~n1.optifix.png" "%~n1.png" >nul
         choice /T:N,1 > NUL
         cecho {0x20}finished.
         choice /T:N,1 > NUL )
    
    cecho {silver}{\n\n}
    goto :EOF

    Comment


      #3
      and it continues here (just copy+paste it at the end of the first part or use the script from the zip file):

      Code:
      :: #################################################################################
      :: #################################################################################
      :dellist
      SETLOCAL
      
      set localcompare=%2
      cecho {gray} 
      
      if %~z1 LSS %2 cecho {lime}
      if %~z1 GTR %2 cecho {red}
      if %3==1 cecho {red}
      if %3==13 cecho {aqua}
      if not exist %1 cecho {red} 
      
      cecho {\n}{0x20}{0x20} !app%3! {0x20}{0x20}
      
         call :StrLength %~z1
         set /a padding="!filesizelength! - !StrLength!"
         for /l %%X in (1,1,!padding!) do cecho {0x20}
      
      cecho %~z1
      if %~z1 LSS %2 (
         set /a reduction="(%2 - %~z1)*100/%4"
         cecho {0x20}{0x20} -!reduction! %%
         if %3==3 cecho {0x20} (lossy^^!^)
         set localcompare=%~z1
      )
      if %3==12 cecho {gray}{\n} ---------------------------------------------------
      
      ENDLOCAL&set comparewith=%localcompare%
      goto :eof
      
      
      :chkbiggerzero
      SETLOCAL
      
      ENDLOCAL
      goto :eof
      
      :: #################################################################################
      :calcfinalratio
      set /a redu="(%~z2 - %~z1)*100/%~z1"
      cecho {0x20}{0x20} !redu! %%{\n}
      goto :eof
      
      :: #################################################################################
      :comparesize
      SETLOCAL
      if %~z2 GTR %~z1 (cecho {red}) else (cecho {green})
      ENDLOCAL
      goto :eof
      
      :: #################################################################################
      :results
      SETLOCAL
      if not exist %2 (copy %1 %2 >nul)
      echo.
      cecho {white} 
      
      if %~z2 EQU %~z1 (
      echo --------------------------------------------------------------- & cecho {yellow}
      echo ----- NO REDUCTION ---- inputsize = outputsize = %~z1 & cecho {white}
      echo ---------------------------------------------------------------)
      
      IF %~z2 GTR %~z1 (
      echo --------------------------------------------------------------- & cecho {red}
      echo ^^!^^!^^!^^!^^!^^!^^!^^!^^!^^!^^!  WARNING: OUTPUT BIGGER THAN INPUT  ^^!^^!^^!^^!^^!^^!^^!^^!^^!^^!^^!^^!^^!^^!^^! & cecho {white}
      echo ---------------------------------------------------------------
      echo. & cecho {gray}
      echo  INPUT FILE:  %1
      echo  INPUT SIZE:  %~z1
      echo. & cecho {silver}
      echo OUTPUT FILE:  %2 & cecho {red}
      echo OUTPUT SIZE:  %~z2 & cecho {white}
      echo.
      echo ---------------------------------------------------------------
      if /i "%~x1" EQU ".png" (
      cecho ---------- {red}^^!^^!^^!^^!^^!^^!^^!^^!^^!  KEEPING INPUT FILE  ^^!^^!^^!^^!^^!^^!^^!^^!^^!^^!^^!^^!{white} ----------{\n}
      cecho ---------------------------------------------------------------{\n}
      copy %1 %2 >nul))
      
      
      if %~z2 LSS %~z1 (
      cecho ---------------- {lime}FILE SUCCESSFULLY COMPRESSED{white} -----------------{\n\n}
      cecho  {gray} INPUT SIZE: %~z1 {\n}
      cecho {silver}OUTPUT SIZE: %~z2 {\n}
      set /a redu1="(%~z2 - %~z1)*100/%~z1"
      set /a redu2="(%~z2 - %~z3)*100/%~z3"
      set /a diff=%~z2 - %~z1
      
      cecho {green} DIFFERENCE: !diff! {\n}
      
      cecho {lime}{0x20} REDUCTION:{0x20}
      if !redu1! GTR -10 cecho {0x20}
      if !redu1! == 0 cecho -
       cecho !redu1! %% {\n}
      
      cecho {0x20} TOTAL RED:{0x20}
      if !redu2! GTR -10 cecho {0x20} 
      if !redu2! == 0 cecho -
      cecho !redu2! %% {\n\n}{white}
      echo ---------------------------------------------------------------)
      
      call :listchunks %2
        
      ENDLOCAL
      goto :EOF
      
      :: #################################################################################
      :pngchk
      SETLOCAL
      
      for /f "tokens=* delims=" %%a in ('pngcheck -ftvv %1') do set str=%%a& set str=!str:^|=-!& call :colorresults "!str!" gray
      
      cecho {white} --------------------------------------------------------------- {\n\n}
      
      ENDLOCAL
      goto :EOF
      
      :: #################################################################################
      :colorresults
      setlocal
      set err=0
      set str=%~1
      cecho {%2}
      
      if /i "!str:~0,5!"  == "file:"        cecho {teal}
      if /i "!str:~0,7!"  == "  chunk"      cecho {white}
      if /i "!str:~-5!"   == "aced "        cecho {fuchisa}
      if /i "!str:~-8!"   == "palette "     cecho {\n}{lime}
      if /i "!str:~0,9!"  == "no errors"    cecho {\n}{lime} --{0x3E}{0x20}
      if /i "!str:~0,6!"  == "  warn"      (cecho {\n}{red}{0x20}{0x21}{0x21}{0x21}{0x21}{0x21}{0x21}{0x21}{0x21}{0x20}) & set err=1
      if /i "!str:~0,10!" == "there were"  (cecho {\n}{red}{0x20}{0x21}{0x21}{0x21}{0x21}{0x21}{0x21}{0x21}{0x21}{0x20}) & set err=1
      if /i "!str:~0,7!"  == "  error"     (cecho {\n}{red}{0x20}{0x21}{0x21}{0x21}{0x21}{0x21}{0x21}{0x21}{0x21}{0x20}) & set err=1
      if /i "!str:~0,5!"  == "error"       (cecho {\n}{red}{0x20}{0x21}{0x21}{0x21}{0x21}{0x21}{0x21}{0x21}{0x21}{0x20}) & set err=1
      if /i "!str:~0,7!"  == "warning"     (cecho {\n}{red}{0x20}{0x21}{0x21}{0x21}{0x21}{0x21}{0x21}{0x21}{0x21}{0x20}) & set err=1
      if /i "!str:~0,8!"  == "pngsplit"     cecho {silver}
      if /i "!str:~0,7!"  == "png-fix"      cecho {silver}
      if /i "!str:~-6!"   == ".png: "       cecho {\n}
      if /i "!str:~-6!"   == "image "       cecho {silver}
      if /i "!str:~0,7!"  == "optipng"      cecho {white}
      if /i "!str:~-10!"  == "decrease) "   cecho {lime}
      if /i "!str:~-9!"   == "decrease)"    cecho {lime}
      if /i "!str:~-10!"  == "increase) "   cecho {red}
      if /i "!str:~-9!"   == "increase)"    cecho {red}
      if /i "!str:~-9!"   == "detected "    cecho {\n}{purple}
      if /i "!str:~0,5!"  == "input"        cecho {\n}
      if /i "!str:~0,12!" == "output file:" cecho {\n}
      if /i "!str:~0,7!"  == "the col"      cecho {silver}
      if /i "!str:~0,11!" == "output idat"  cecho {silver}
      if /i "!str:~0,6!"  == "      "       cecho {gray}
      if /i "!str:~-9!"   == "reduced. "    cecho {lime}
      
      echo %~1
      if %err%==1 pause >nul
      
      endlocal
      goto :eof
      
      :: #################################################################################
      :listchunks
      SETLOCAL
      
      set col0=grayscale
      set col1=not_valid
      set col2=RGB
      set col3=palette
      set col4=grayscale+alpha
      set col5=not_valid
      set col6=RGB+alpha
      
      call :StrLength %~z1
      set filesizelength=%StrLength%
      
      cecho {white}
      echo.
      for /f "tokens=1,2*" %%E in ('advpng -l %1') DO (
         if not "%%G"=="" set ihdr=%%G
         cecho {white} %%E {gray}
      
         call :StrLength %%F
         set /a padding="%filesizelength% - !StrLength!"
         for /l %%X in (1,1,!padding!) do cecho {0x20}
      
         cecho %%F{\n})
      
      for /f "tokens=1-26 delims=: " %%a in ("%ihdr%") DO (
      
         cecho {white}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}
         cecho {0x20}{0x20}{0x20}{0x20}{0x20} {0x20}{0x20}{0x20}{0x20}{0x20} %%m:
         if %%n==0 (cecho {lime}) else (cecho {red})
         cecho {0x20}%%n {\n}
         cecho {white}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{white}%%e:{purple} %%f
         cecho {0x20}{0x20}{0x20}{white}%%i:
         if %%j==0 (cecho {gray}) else (cecho {red})
         cecho {0x20}%%j {0x20}{0x20}{0x20}{0x20}{white}%%a: {blue}%%b{\n}{white}
         cecho {0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}%%g:{fuchisa} %%h{white}
         cecho {0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}{0x20}%%k:
         if %%l==0 (cecho {gray}) else (cecho {red})
         cecho {0x20}%%l {0x20}{0x20}{0x20}{white}%%c:{blue} %%d{\n}{white}
         cecho ---------------------------------------------------------------{\n}
      
      
         set /a colors="1 << %%f"
         REM (same as:) set colors=2& for /l %%X in (2,1,%%f) do set /a colors=!colors! * 2
      
         set colortype=!col%%h!
         if "!colortype!"=="not_valid" set multiplier=0
         if "!colortype!"=="palette" set multiplier=1
         if "!colortype:~0,4!" == "gray" set multiplier=1
         if "!colortype:~0,3!" == "RGB" set multiplier=!colors!
      
         set /a colors=!colors! * !multiplier! * !multiplier!
      
         cecho {fuchisa}color_type %%h [=!colortype!]{0x20}{gray}@{purple} depth %%f = !colors! colors{\n}
         if %%n==0 (cecho {lime}{0x20}{0x20}interlace method 0 = none [smaller file size]) else (cecho {red}{0x20}{0x20}interlace method %%n = Adam7 interlacing [7-pass] =^> bigger file size!)
         cecho {\n}{gray}{0x20}{0x20}filtering method 0 = adaptive filtering with 5 basic filters{\n}
         cecho compression method 0 = deflate/inflate compression{\n}
         cecho {white}---------------------------------------------------------------{\n\n}
         
         set colortype=%%h
      )
         
      ENDLOCAL& set currentcolortype=%colortype%& set currentcolors=%colors%
      goto :eof
      
      
      :: #################################################################################
      :StrLength 
      set WorkString=%*
      set StrLength=0
      :StrLengthLoop
      if not "!WorkString:~%StrLength%,1!"=="" set /a StrLength += 1&goto StrLengthLoop
      goto :eof
      
      :: #################################################################################
      :storefilesize 
      call :StrLength %~z1
      set filesizelength=%StrLength%
      goto :eof

      Comment


        #4
        And please no comments about how bad the script is.
        I never wrote any batch scripts before, I just needed it for this specific purpose ...

        Comment


          #5
          I use PNG crush on my Windows Shell menu. It works fine. I'm sure its a lot simpler.
          Before you post ... Edit your profile • IrfanView 4.62 • Windows 10 Home 19045.2486

          Irfan PaintIrfan View HelpIrfanPaint HelpRiot.dllMore SkinsFastStone CaptureUploads

          Comment


            #6
            Of course it works fine and is simple.
            • But if you want it simple, just use IrfanView's internal (built-in) save as ... >> png (with or without pngout plugin).
            • If you want maximum compression, use my script.


            The usage of my script is as simple as pngcrush's usage:

            pngopti [IMAGE] [-EXTREME]

            And BTW, pngcrush is one of the converters used by my script. Just hit CTRL+F and search the code above.

            Comment


              #7
              I'd have to say, why is maximum compression so important nowadays?

              Comment


                #8
                Originally posted by Skippybox View Post
                I'd have to say, why is maximum compression so important nowadays?
                Image compression is still important for websites. Not everyone is on broadband and even if you are, pages still load faster if they're optimised properly.

                However, I don't see much benefit in shaving another 0.1% off the size of an image, though 10% is certainly worthwhile. That's why I like PNGcrush. It is quick and sometimes gets worthwhile benefits, depending on the source of the PNG image.

                FastStone Capture tends to compress PNG very well anyway, but if you save from other programs there is often room for improvement. Reducing to 256 colours saves the most, and that is often good enough for dialogue boxes.

                A quick test of the current window save with printscreen:

                Saved from IrfanView = 155 Kbytes
                Compressed with PNG crush = 125 Kbytes
                Saved from FastStone Capture = 130 Kbytes
                Compressed that with PNG crush = 124 Kbytes
                Reduce to 256 colours = 57 Kbytes
                Compress that with PNG crush = 54 Kbytes

                So depending on the source image, further compression is sometimes not worthwhile. I would say that 1% is not worth the few seconds that it takes, but for 20% it certainly is worth doing — perhaps for 5% too.
                Before you post ... Edit your profile • IrfanView 4.62 • Windows 10 Home 19045.2486

                Irfan PaintIrfan View HelpIrfanPaint HelpRiot.dllMore SkinsFastStone CaptureUploads

                Comment


                  #9
                  Bhikkhu Pesala, if you still have the "current window saved with printscreen", could you attach it here please, so that I can compare? thanks.

                  Comment


                    #10
                    Originally posted by Skippybox View Post
                    I'd have to say, why is maximum compression so important nowadays?
                    Don't forget the storage space even if those days you've got a 32kb sector on HDD, on floppy is still 512 bytes and one bytes less or more makes a difference on how much space is used for a file. Well you might say I don't care about space, I got CD's or DVD's, xxxGB HDD. Thinking at a great scale makes the difference. And gain bandwidth is something you might appreciate If you have a webserver serving lots of users. Why not more in same bandwidth?
                    Imi este indiferent ce cred ceilalti despre mine, caci oricum fiecare crede ce-i convine lui si nu ceea ce e real,
                    doar ca mi-ar fi placut sa ma vada asa cum sint de fapt, nu asa cum poate le-ar placea lor sa creada. Ei au ales deja...

                    ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷··
                    ·· · ·M· · ·I· · ·D· · ·I· · ·· ·· ·M· · ·A· · ·N· · ·I· · ·A· · ·C· · ·S· · ··
                    ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷··

                    Comment


                      #11
                      the ultimate tool for PNG compression optimisation updated (2009.01.23)

                      Here are some difference form above posted "Ultimate tool for PNG compression optimisation" versions of tools used in it and current (23.01.2009) from official webpages. Most of links are related to ftp.mirrorservice.org or official sites.

                      PNGout
                      used - (09.02.2008)
                      latest - (20.11.2008) - DDL

                      OptiPNG
                      - used v0.55 (29.01.2007)
                      - latest 0.6.2 (11.11.2008) - DDL

                      PNG crush
                      - used v1.6.4 (21.11.2007)
                      - latest available for download v1.6.10 Win (28.09.2008) - DDL
                      - latest v1.6.3.13 (07.01.2009) (no binary available at this moment)

                      PNG Rewrite
                      - used v1.2.1 (??.??.???)
                      - latest v1.3.0 (17.12.2008) - DDL

                      advPNG
                      - latest/used v1.15 (DOS-Pentium) (01.11.2005) - DDL

                      deflopt
                      - latest/used v2.07 (05.09.2007) - DDL

                      PNG check (3 files) - DDL
                      * pngcheck.exe
                      - latest/used v2.3.0 (07.07.2007) compiled with zLib 1.2.3
                      * png-fix-IDAT-windowsize.exe
                      - latest/used v0.5 (01.08.2005)
                      * pngsplit.exe
                      - latest/used v0.6 beta (11.02.2007)

                      External programs:
                      ImageMagick
                      - latest version v6.4.8-8 (22.01.2009) - DDL HTTP / FTP


                      Download "Ultimate tool for PNG compression optimisation" updated 23.01.2009:
                      attachment / MIDI MANiACS @Xhost

                      * Note: pngopti.cmd changes:
                      - path for ImageMagick has been changed to C:\Program Files\ImageMagick\ (default install folder of program)
                      - various version tools have been updated
                      Attached Files
                      Last edited by Jaff; 23.01.2009, 05:44 AM. Reason: added download links
                      Imi este indiferent ce cred ceilalti despre mine, caci oricum fiecare crede ce-i convine lui si nu ceea ce e real,
                      doar ca mi-ar fi placut sa ma vada asa cum sint de fapt, nu asa cum poate le-ar placea lor sa creada. Ei au ales deja...

                      ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷··
                      ·· · ·M· · ·I· · ·D· · ·I· · ·· ·· ·M· · ·A· · ·N· · ·I· · ·A· · ·C· · ·S· · ··
                      ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷··

                      Comment


                        #12
                        I would add : why is any maximum so important nowadays ?
                        Concerning filesize : besides quick loading of a web-page, also with image attachments to a mail.
                        Due to intermediate en- and de-coding is the file growing to 150 %.

                        Bhikkhu talks about reducing to 256 colours, and he's right. With some scans of 'graphic' design it's possible to go down to 16 colours, or even 4. PNG can handle that.
                        0.6180339887
                        Rest In Peace, Sam!

                        Comment


                          #13
                          Not only reduction to 256 colors is best also converting to grayscale in some cases of whole/partial image (without dithering) best fot text parts.
                          Try using PNGs instead of JPEGs for scanned pages from books & some other stuff.
                          Diffence of files size is visible from start even before optimising PNGs.
                          Imi este indiferent ce cred ceilalti despre mine, caci oricum fiecare crede ce-i convine lui si nu ceea ce e real,
                          doar ca mi-ar fi placut sa ma vada asa cum sint de fapt, nu asa cum poate le-ar placea lor sa creada. Ei au ales deja...

                          ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷··
                          ·· · ·M· · ·I· · ·D· · ·I· · ·· ·· ·M· · ·A· · ·N· · ·I· · ·A· · ·C· · ·S· · ··
                          ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷··

                          Comment


                            #14
                            The ultimate tool for PNG compression optimisation updated (2009.09.26)

                            Updated:

                            PNGout
                            latest - (22.09.2009) - DDL

                            OptiPNG
                            - latest 0.6.3 (18.05.2009) - DDL

                            PNG crush
                            - latest available for download v1.6.15 Win (20.04.2009) - DDL
                            - latest v1.7.2 (10.09.2009) (no binary available at this moment)

                            External programs:
                            ImageMagick
                            - latest version v6.5.6-4 (22.09.2009) - DDL HTTP / FTP


                            Download "Ultimate tool for PNG compression optimisation" updated 26.09.2009:
                            attachment / MIDI MANiACS @Xhost

                            * Note: pngopti.cmd changes:
                            - path for ImageMagick has been changed to C:\Program Files\ImageMagick\ (default install folder of program)
                            - various version tools have been updated
                            Attached Files
                            Imi este indiferent ce cred ceilalti despre mine, caci oricum fiecare crede ce-i convine lui si nu ceea ce e real,
                            doar ca mi-ar fi placut sa ma vada asa cum sint de fapt, nu asa cum poate le-ar placea lor sa creada. Ei au ales deja...

                            ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷··
                            ·· · ·M· · ·I· · ·D· · ·I· · ·· ·· ·M· · ·A· · ·N· · ·I· · ·A· · ·C· · ·S· · ··
                            ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷·· ·· · · · ·· ··÷¦÷··

                            Comment


                              #15
                              thanks for the PNG optimization efforts I wish it did not rely on batch files, however.


                              Originally posted by Bhikkhu Pesala View Post
                              I Not everyone is on broadband
                              Those who are not should stick to the Lynx browser or keep to using email. The web was NEVER designed with analog modem users in mind :P

                              I upload PNG images to my online gallery. Camera -> JPG is one lossy too many. I'll suffer until RAW is commonplace
                              Last edited by Zymex; 03.10.2009, 10:55 AM.
                              purity matters

                              Comment

                              Working...
                              X