Path: csiph.com!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.034 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'socket': 0.05; 'pil': 0.07; 'here?': 0.09; 'subject:PIL': 0.09; 'doing:': 0.16; 'oct': 0.16; 'subject:requests': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'requests': 0.18; 'sender:addr:gmail.com': 0.18; 'module': 0.19; 'import': 0.21; 'pass': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'object,': 0.27; "doesn't": 0.28; 'image,': 0.29; "i'm": 0.29; 'file': 0.32; 'getting': 0.33; 'says': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'but': 0.36; 'url:org': 0.36; 'anything': 0.36; 'charset:us-ascii': 0.36; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'url:en': 0.38; 'gives': 0.39; 'to:addr:python.org': 0.39; 'takes': 0.39; 'end': 0.40; 'you.': 0.61; 'here:': 0.62; 'received:117': 0.75; 'subject:get': 0.81; '(roy': 0.84; 'email addr:panix.com': 0.84; 'smith)': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-type; bh=HiI9SsyQh/8rbw9pl9Rh/DD/n2XlcI62eprTGSidBH8=; b=Dj2iAwr31S8ViZRPf94GXuigIbl90BkVf/S2rro1rvCVOc68vpTUcIT/sGLM+wnr+v wX0waJer/TUDtKWGUWZGXGTgRMgMmeOJulsAwZut0zn58ye0Y85oijlP1ISQsCivDt9I ts5DwjAADtgtZMUk6mzXwDP1tf/6LJRoGTTco3r6Xomwl3Dw3xsyfT/v8/EvJ8zsyHb+ j4h4oQzQ+J9bzT5HgQ6hfJF2qYt690gEluyereZvFoh+E3e/Lu2sDLxeLmVw2HW7D1z2 TmRXTIrYXen+KVNn7EQLz8sdSDd7p9wxZMAos3RaugmQTLOH8I8J9BomS3WChW+hTOUm +elA== Sender: Kushal Kumaran From: Kushal Kumaran To: python-list@python.org Subject: Re: PIL and requests don't get along In-Reply-To: References: User-Agent: Notmuch/0.12 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Wed, 24 Oct 2012 11:25:53 +0530 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351058163 news.xs4all.nl 6877 [2001:888:2000:d::a6]:49433 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32002 On 23 Oct 2012 14:06:59 -0400, roy@panix.com (Roy Smith) wrote: > I have a url from which I can get an image. I want to use PIL to > manipulate that image. Getting the image is easy: > > >>> import requests > >>> r = requests.get(url) > > There's a bunch of factory functions for Image, but none of them seem > to take anything that requests is willing to give you. Image.new() > requires that you pass it the image size. Image.open() takes a file > object, but > > >>> Image.open(r.raw) > > doesn't work because r.raw gives you a socket which doesn't support > seek(). I end up doing: > > >>> r = requests.get(url) > >>> data = cStringIO.StringIO(r.content) > >>> image = Image.open(data) > > which works, but it's gross. Is there something I'm missing here? That is pretty much what the requests module documentation says here: http://docs.python-requests.org/en/latest/user/quickstart/#binary-response-content -- regards, kushal