Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #59481
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.008 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'string': 0.09; '8bit%:30': 0.09; 'pil': 0.09; 'pixel': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'file-like': 0.16; 'finney': 0.16; 'latter,': 0.16; 'metadata.': 0.16; 'mode,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Converting': 0.16; 'subject:image': 0.16; 'library': 0.18; 'import': 0.22; 'header:User-Agent:1': 0.23; 'byte': 0.24; 'bytes': 0.24; 'specify': 0.24; 'string,': 0.24; 'shown': 0.26; 'header:X-Complaints-To:1': 0.27; 'usually': 0.31; 'extract': 0.31; 'writes:': 0.31; 'allows': 0.31; 'class': 0.32; 'front': 0.32; 'url:python': 0.33; 'but': 0.35; 'subject:data': 0.36; 'url:org': 0.36; 'should': 0.36; 'wrong': 0.37; 'turn': 0.37; 'ben': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'read': 0.60; 'new': 0.61; 'url:3': 0.61; 'skip:\xe2 10': 0.65; '8bit%:40': 0.68; 'reads': 0.68; '8bit%:24': 0.84; 'usage.': 0.84; '\xe2\x80\xa6': 0.84; 'whereas': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Ben Finney <ben+python@benfinney.id.au> |
| Subject | Re: Converting hex data to image |
| Date | Fri, 15 Nov 2013 08:29:02 +1100 |
| References | <CALVX-oYZzX8CEvP58=mfyk2yYXFRkk4e0t66bFn8na-h_BNpHw@mail.gmail.com> <7w61ruwv0q.fsf@benfinney.id.au> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| X-Gmane-NNTP-Posting-Host | rasputin.madmonks.org |
| X-Public-Key-ID | 0xAC128405 |
| X-Public-Key-Fingerprint | 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 |
| X-Public-Key-URL | http://www.benfinney.id.au/contact/bfinney-gpg.asc |
| X-Post-From | Ben Finney <bignose+hates-spam@benfinney.id.au> |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) |
| Cancel-Lock | sha1:9bO2DYitrNm7iuxQ2lM7nLc7fqE= |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2626.1384464557.18130.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1384464557 news.xs4all.nl 15940 [2001:888:2000:d::a6]:55863 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:59481 |
Show key headers only | View raw
Ben Finney <ben+python@benfinney.id.au> writes:
> To turn a byte string into a file-like object for use with PIL, extract
> the byte string as ‘image_data’, use the standard library ‘io.StringIO’
> class <URL:http://docs.python.org/3/library/io.html#io.StringIO>, then
> create a new ‘PIL.Image’ object by reading from that pseudo-file::
My apologies, I showed the wrong usage. This should work::
import io
import PIL
photo_data = # … get the byte string from wherever it is …
photo_infile = io.StringIO(photo_data)
photo_image = PIL.Image.open(photo_infile)
That is, ‘PIL.Image.frombytes’ 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 ‘PIL.Image.open’ reads the data from
a file-like object and parses all the metadata. So you usually want to
use the latter, as shown here.
--
\ “People's Front To Reunite Gondwanaland: Stop the Laurasian |
`\ Separatist Movement!” —wiredog, http://kuro5hin.org/ |
_o__) |
Ben Finney
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Converting hex data to image Ben Finney <ben+python@benfinney.id.au> - 2013-11-15 08:29 +1100
csiph-web