可能重复:
如何使用python检查目录中所有图像的尺寸?
我想知道是否有人知道如何在python sript中读取图像的总像素数.你能提供和举例吗?
非常感谢.
小智 12
这是一个例子:
from PIL import Image
def get_num_pixels(filepath):
width, height = Image.open(filepath).size
return width*height
print get_num_pixels("/path/to/my/file.jpg")
Run Code Online (Sandbox Code Playgroud)
这是您要求的示例:
from PIL import Image
import os.path
filename = os.path.join('path', 'to', 'image', 'file')
img = Image.open(filename)
width, height = img.size
print "Dimensions:", img.size, "Total pixels:", width * height
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21842 次 |
| 最近记录: |