File size: 706 Bytes
113dbd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# save images in 1-10 compresion timing the results
from pathlib import Path
from time import time
def test_compression():
    save_dir = Path("./imgs-sd/test/")
    save_dir.mkdir(exist_ok=True, parents=True)

    from PIL import Image

    image = Image.open("/home/lee/code/sdif/imgs-sd/Woody.png").convert("RGB")
    start = time()

    image.save(save_dir / f"woody-.webp", format="webp")
    end = time()
    print(f"Time to save image with quality : {end - start}")

    for i in range(0, 100):
        start = time()

        image.save(save_dir / f"woody-{i}.webp", quality=i, optimize=True, format="webp")
        end = time()
        print(f"Time to save image with quality {i}: {end - start}")