Python method to get remote image size and dimensions

  • 2020-04-02 14:46:07
  • OfStack

This example shows how python can get remote image sizes and dimensions. Share with you for your reference. Specific analysis is as follows:

This code opens the remote image through urllib2, reads the file contents through cStringIO, and reads the image file information without saving it to disk


#!/usr/bin/env python
#encoding=utf-8
import cStringIO, urllib2, Image
url = '//www.jb51.net/images/logo.gif'
file = urllib2.urlopen(url)
tmpIm = cStringIO.StringIO(file.read())
im = Image.open(tmpIm)
print im.format, im.size, im.mode

I hope this article has helped you with your Python programming.


Related articles: