Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #59483 > unrolled thread

Re: Converting hex data to image

Started byShyam Parimal Katti <spk265@nyu.edu>
First post2013-11-14 17:22 -0500
Last post2013-11-14 17:22 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Converting hex data to image Shyam Parimal Katti <spk265@nyu.edu> - 2013-11-14 17:22 -0500

#59483 — Re: Converting hex data to image

FromShyam Parimal Katti <spk265@nyu.edu>
Date2013-11-14 17:22 -0500
SubjectRe: Converting hex data to image
Message-ID<mailman.2627.1384467786.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

Perfect. Thank you @Ben and @Tim


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

> 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
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web