Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.031 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'string': 0.09; 'pil': 0.09; 'pixel': 0.09; 'cc:addr:python-list': 0.11; 'file-like': 0.16; 'finney': 0.16; 'latter,': 0.16; 'metadata.': 0.16; 'mode,': 0.16; 'perfect.': 0.16; 'subject:Converting': 0.16; 'subject:image': 0.16; 'wrote:': 0.18; 'library': 0.18; 'thu,': 0.19; 'import': 0.22; 'cc:addr:python.org': 0.22; 'byte': 0.24; 'bytes': 0.24; 'specify': 0.24; 'string,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'shown': 0.26; 'header :In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'usually': 0.31; 'extract': 0.31; 'writes:': 0.31; 'allows': 0.31; 'class': 0.32; 'front': 0.32; 'received:209.85.212': 0.32; 'url:python': 0.33; 'received:209.85': 0.35; 'but': 0.35; 'received:google.com': 0.35; '14,': 0.36; 'subject:data': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'should': 0.36; 'wrong': 0.37; 'turn': 0.37; 'received:209': 0.37; 'skip:& 10': 0.38; 'thank': 0.38; 'ben': 0.38; 'nov': 0.38; 'url:library': 0.38; 'pm,': 0.38; 'skip:p 20': 0.39; 'url:mail': 0.40; 'read': 0.60; 'new': 0.61; 'url:3': 0.61; '8bit%:10': 0.64; 'charset:windows-1252': 0.65; 'reads': 0.68; '4:29': 0.84; 'skip:\x91 10': 0.84; 'usage.': 0.84; 'whereas': 0.91; '2013': 0.98 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=yEX6owZYDhxVpe3r6czRmfso9hG/qpuZ4Ts2x1LijMI=; b=Op36nuMpIhnF9CNkbVioHxSDCRsVi2Deayz6kuKJM1BJ13JwNobmK9d/5XZIxPqEDO R7zdYNfQCVmSiH2WBgMJbkjb6xkIw8NedUXQZXfdH6dZ3Lnp5wsJsN6xW3HP77k0ffmz 08JP1IRbJLzQu7FSRGUbDVsdUI+MDNmLu+Lr6NeCtySLvQEt5g/OArw7rYCjn05ejGud ZUSB8R87y6RQIJ5AjZOtG0eTojkOdxqaMDfnvlqsNqDZ/QObjyl4toVkNJPMsv0nfGi6 GNXDy1iP56n9/uiRYBb6U57rF4oqEv50AvcrHYNlDHCBJsMHJElEOlcpQKWZ7/NM7Oiw 8tJQ== X-Gm-Message-State: ALoCoQnHOhIeyDO2jwfLCL7pmdxlQG14cI24I60K7W1xLwWhrS1OUMvckxbsRwVk2wWrVORtgZsc MIME-Version: 1.0 X-Received: by 10.52.185.8 with SMTP id ey8mr181342vdc.107.1384467778165; Thu, 14 Nov 2013 14:22:58 -0800 (PST) In-Reply-To: <7w1u2iwu3l.fsf@benfinney.id.au> References: <7w61ruwv0q.fsf@benfinney.id.au> <7w1u2iwu3l.fsf@benfinney.id.au> Date: Thu, 14 Nov 2013 17:22:58 -0500 Subject: Re: Converting hex data to image From: Shyam Parimal Katti To: Ben Finney Content-Type: multipart/alternative; boundary=bcaec54866e21eeea104eb2a8605 Cc: python-list@python.org 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: 109 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1384467787 news.xs4all.nl 16008 [2001:888:2000:d::a6]:44900 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:59483 --bcaec54866e21eeea104eb2a8605 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Perfect. Thank you @Ben and @Tim On Thu, Nov 14, 2013 at 4:29 PM, Ben Finney wro= te: > Ben Finney writes: > > > To turn a byte string into a file-like object for use with PIL, extract > > the byte string as =91image_data=92, use the standard library =91io.Str= ingIO=92 > > class , then > > create a new =91PIL.Image=92 object by reading from that pseudo-file:: > > My apologies, I showed the wrong usage. This should work:: > > import io > > import PIL > > photo_data =3D # =85 get the byte string from wherever it is =85 > photo_infile =3D io.StringIO(photo_data) > photo_image =3D PIL.Image.open(photo_infile) > > That is, =91PIL.Image.frombytes=92 allows you to read the bytes from a by= te > string, but requires you to also specify metadata about the image data > (format, pixel mode, size), whereas =91PIL.Image.open=92 reads the data f= rom > a file-like object and parses all the metadata. So you usually want to > use the latter, as shown here. > > -- > \ =93People's Front To Reunite Gondwanaland: Stop the Laurasian = | > `\ Separatist Movement!=94 =97wiredog, http://kuro5hin.org= / | > _o__) | > Ben Finney > > -- > https://mail.python.org/mailman/listinfo/python-list > --bcaec54866e21eeea104eb2a8605 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable
Perfect. Thank you @Ben and @Tim


On Thu, Nov 14, 2013 at 4:29 = PM, Ben Finney <ben+python@benfinney.id.au> wrote:<= br>
Ben Finney <ben+python@benfinney.id.au> wri= tes:

> To turn a byte string into a file-like object for use with PIL, extrac= t
> the byte string as =91image_data=92, use the standard library =91io.St= ringIO=92
> class <URL:http://docs.python.org/3/library/io.html#io.Stri= ngIO>, then
> create a new =91PIL.Image=92 object by reading from that pseudo-file::=

My apologies, I showed the wrong usage. This should work::

=A0 =A0 import io

=A0 =A0 import PIL

=A0 =A0 photo_data =3D # =85 get the byte string from wherever it is =85 =A0 =A0 photo_infile =3D io.StringIO(photo_data)
=A0 =A0 photo_image =3D PIL.Image.open(photo_infile)

That is, =91PIL.Image.frombytes=92 allows you to read the bytes from a byte=
string, but requires you to also specify metadata about the image data
(format, pixel mode, size), whereas =91PIL.Image.open=92 reads the data fro= m
a file-like object and parses all the metadata. So you usually want to
use the latter, as shown here.

--
=A0\ =A0 =A0 =A0 =A0 =93People's Front To Reunite Gondwanaland: Stop th= e Laurasian |
=A0 `\ =A0 =A0 =A0 =A0 =A0 =A0 =A0Separatist Movement!=94 =97wiredog, http://kuro5hin.org/ |
_o__) =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0|
Ben Finney

--
https://mail.python.org/mailman/listinfo/python-list

--bcaec54866e21eeea104eb2a8605--