如何在python中获取调用图片的大小?

发布时间:2022-06-08 09:53:35 人气:128 作者:多测师

  python中获取图片大小需要使用Pillow库中的img.size方法。

  安装Pillow

  pip install pillow

  获取本地图片的大小:

  import os

  from PIL import Image

如何在python中获取调用图片的大小?

  path = os.path.join(os.getcwd(),"23.png")

  img = Image.open(path)

  print img.format # PNG

  print img.size # (3500, 3500)

  获取远程图片的大小:

  path = "http://h.hiphotos.baidu.com/image/pic/item/c8ea15ce36d3d5397966ba5b3187e950342ab0cb.jpg"

  file = urllib2.urlopen(path)

  tmpIm = cStringIO.StringIO(file.read())

  img = Image.open(tmpIm)

  print img.format # JPEG

  print img.size # (801, 1200)

  以上内容为大家介绍了如何在python中获取调用图片的大小?希望对大家有所帮助,如果想要了解更多Python相关知识,请关注多测师。https://www.e70w.com/xwzx/


返回列表
在线客服
联系方式

热线电话

17727591462

上班时间

周一到周五

二维码
线