How to run guetzli on all jpeg images in a folder and subfolders

I just talk https://github.com/google/guetzli - And I would like to write a script to run it on all jpeg images in a windows project.

How would I loop, all the files in the folder and subfolder and get the relative paths for entering the command? Finally, since guetzli is slow enough, is there any way to wait for the completion of the execution or put a delay?

Thanks Lewis

+4
source share
2 answers

For everyone who is interested, this is the code I went to,

setlocal disableDelayedExpansion
for /f "delims=" %%A in ('forfiles /s /m *.jpg /c "cmd /c echo @relpath"') do 
(
  set "file=%%~A"
  setlocal enableDelayedExpansion
  echo !file:~2!
  CALL "guetzli.exe" --quality 85 !file:~2! !file:~2!
  endlocal
)

Just put it in the root directory with guetzli executable

+2
source

Python . -. jpgs , . = 95 - , 90. 6,4 2,2 25 420280 JPG ( ). = 85 1,7 , 0,5% . Stil - Guetzli . . -

import os
import time
import subprocess

files = os.listdir('./')

jpgs = []
for file in files:
    if file[len(file)-3:] != 'jpg':
        continue
    try:
        fnum = int(file.split('.')[0])
    except:
        continue
    jpgs.append(file)
    jpgs.sort()


todo = len(jpgs)
done = 1
print '# %d = todo' % (todo)
start_tot = time.time()
for jpg in jpgs:
    fnum = int(jpg.split('.')[0])
    cmd = 'guetzli --quality 95 %d.jpg %d_g.jpg' % (fnum, fnum)
    print '# %d of %d' % (done, todo)
    print '# %s' % (cmd)
    start_img = time.time()
    subprocess.call(cmd, shell=True)
    t_this = time.time() - start_img
    t_tot = (time.time() - start_tot)
    avg = t_tot / float(done)
    done += 1
    print '#---%d done: %0.2f sec, %0.2f avgSec, %0.2f minTot' % ( fnum, t_this, avg, t_tot/60.0)
#end
+1

Source: https://habr.com/ru/post/1672583/


All Articles