python从网络读取图片并直接进行处理的方法

WBOY
Release: 2016-06-10 15:11:50
Original
1515 people have browsed it

本文实例讲述了python从网络读取图片并直接进行处理的方法。分享给大家供大家参考。具体实现方法如下:

下面的代码可以实现从网络读取一张图片,不需要保存为本地文件,直接通过Image模块对图片进行处理,这里使用到了cStringIO库,主要是把从网络读取到的图片数据模拟成本地文件。

import urllib2
import Image
import cStringIO
def ImageScale(url,size):
  file = cStringIO.StringIO(urllib2.urlopen(url).read())
  img = Image.open(file)
  img.show()

Copy after login

希望本文所述对大家的Python程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template