python batch image pixel size and dpi

 Use pillow

Open the file, traverse the image names in the file, and modify the access address.

Modify the picture. It's like a fake image traversal, which is the current level.

run。

from PIL import Image
import os

files = os.listdir('./ori_img')
for item in files:
    item = "./ori_img/"+item
    print(item)
    img=Image.open(item)
    img.show()
    width, height = 358, 441
    img = img.resize((width, height))
    img.save(item,dpi = (300.0,300.0))

 

Guess you like

Origin blog.csdn.net/qq_46012097/article/details/127793966