Home > AI > Language > Python > PIL >

resize

Example 1: Image.resize is better than cv2.resize since it can preserve image quality.


import glob
import cv2
from PIL import Image

fs = glob.glob('**/*.png')
for f in fs:
#    img = cv2.imread(f)
#    img = cv2.resize(img, (300, 370))
#    cv2.imwrite(f, img)

    img = Image.open(f)
    img = img.resize((300, 370))
    img.save(f)
    

Leave a Reply