How to convert an image to a piece of code?

Hi, All

Below is a piece of sample code, Its output is an image. My question is: How do we get these code below 'return ’ ?

def GetMondrianData():
return \

'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00 \x08\x06\x00\

\x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00qID
ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a\x82:\x16\

o\xda\x84pB2\x1f\x81Fa\x8c\x9c\x08\x04Z{\xcf\xa72\xbcv\xfa\xc5\x08 \x80r\x80
\xfc\xa2\x0e\x1c\xe4\xba\xfaX\x1d\xd0\xde]S\x07\x02\xd8>\xe1wa-`\x9fQ\xe9\

\x86\x01\x04\x10\x00\(Dk\x1b-\x04\xdc\x1d\x07\x14\x98;\x0bS\x7f\x7f\xf9\x13
\x04\x10@\xf9X\xbe\x00\xc9 \x14K\xc1<={\x00\x00\x00\x00IEND\xaeB`\x82’

Hello,

Hi, All

Below is a piece of sample code, Its output is an image. My question is: How do we get these code below 'return \' ?

See the img2py script that comes with wxPython.

def GetMondrianData():
          return \
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00 \x08\x06\x00\
\x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00qID\
ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a\x82:\x16\
o\xda\x84pB2\x1f\x81Fa\x8c\x9c\x08\x04Z{\xcf\xa72\xbcv\xfa\xc5\x08 \x80r\x80\
\xfc\xa2\x0e\x1c\xe4\xba\xfaX\x1d\xd0\xde]S\x07\x02\xd8>\xe1wa-`\x9fQ\xe9\
\x86\x01\x04\x10\x00\\(Dk\x1b-\x04\xdc\x1d\x07\x14\x98;\x0bS\x7f\x7f\xf9\x13\
\x04\x10@\xf9X\xbe\x00\xc9 \x14K\xc1<={\x00\x00\x00\x00IEND\xaeB`\x82'

Cody

···

On Nov 17, 2008, at 9:53 PM, Roy Liu wrote:

Hello,

> Hi, All
>
>
> Below is a piece of sample code, Its output is an image. My
> question is: How do we get these code below 'return \' ?
>

See the img2py script that comes with wxPython.

>
> def GetMondrianData():
> return \
> '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00
> \x08\x06\x00\
> \x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d
> \x88\x00\x00\x00qID\
> ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a
> \x82:\x16\
> o\xda\x84pB2\x1f\x81Fa\x8c\x9c\x08\x04Z{\xcf\xa72\xbcv\xfa\xc5\x08
> \x80r\x80\
> \xfc\xa2\x0e\x1c\xe4\xba\xfaX\x1d\xd0\xde]S\x07\x02\xd8>\xe1wa-`\x9fQ
> \xe9\
> \x86\x01\x04\x10\x00\\(Dk\x1b-\x04\xdc\x1d\x07\x14\x98;\x0bS\x7f\x7f
> \xf9\x13\
> \x04\x10@\xf9X\xbe\x00\xc9
> \x14K\xc1<={\x00\x00\x00\x00IEND\xaeB`\x82'
>

seems different from code which created by img2py.

···

On Mon, 17 Nov 2008 22:01:17 -0600 Cody Precord <codyprecord@gmail.com> wrote:

On Nov 17, 2008, at 9:53 PM, Roy Liu wrote:

Cody

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

cocobear wrote:

Hello,

Hi, All

Below is a piece of sample code, Its output is an image. My
question is: How do we get these code below 'return \' ?
      

See the img2py script that comes with wxPython.

def GetMondrianData():
          return \
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00
\x08\x06\x00\
\x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d
\x88\x00\x00\x00qID\
ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a
\x82:\x16\
o\xda\x84pB2\x1f\x81Fa\x8c\x9c\x08\x04Z{\xcf\xa72\xbcv\xfa\xc5\x08
\x80r\x80\
\xfc\xa2\x0e\x1c\xe4\xba\xfaX\x1d\xd0\xde]S\x07\x02\xd8>\xe1wa-`\x9fQ
\xe9\
\x86\x01\x04\x10\x00\\(Dk\x1b-\x04\xdc\x1d\x07\x14\x98;\x0bS\x7f\x7f
\xf9\x13\
\x04\x10@\xf9X\xbe\x00\xc9
\x14K\xc1<={\x00\x00\x00\x00IEND\xaeB`\x82'

seems different from code which created by img2py.
  
What does that mean -- "seems different"? It's exactly the same. That
string is not magic. It's just the contents of the GIF file, read into
a string and printed. It's the exact same thing you'd get if you opened
the interpreter and said:
   >>> open('xxx.gif','rb').read()

It just so happens that the printed representation of a string is a
relatively good way to embed the string in source code.

···

On Mon, 17 Nov 2008 22:01:17 -0600 > Cody Precord <codyprecord@gmail.com> wrote:

On Nov 17, 2008, at 9:53 PM, Roy Liu wrote:

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Tim Roberts wrote:

What does that mean -- "seems different"? It's exactly the same. That
string is not magic. It's just the contents of the GIF file, read into
a string and printed. It's the exact same thing you'd get if you opened
the interpreter and said:
   >>> open('xxx.gif','rb').read()

no, it's not -- it's the image read into a wxImage, then dumped in some binary format -- I don't remember which, but it's not GIF.

anyway, the point is the same -- it's a binary representation of the image that wx can deal with.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Tim Roberts wrote:

def GetMondrianData():
          return \
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00 \x08\x06\x00\
\x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d \x88\x00\x00\x00qID\
ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a \x82:\x16\
o\xda\x84pB2\x1f\x81Fa\x8c\x9c\x08\x04Z{\xcf\xa72\xbcv\xfa\xc5\x08 \x80r\x80\
\xfc\xa2\x0e\x1c\xe4\xba\xfaX\x1d\xd0\xde]S\x07\x02\xd8>\xe1wa-`\x9fQ \xe9\
\x86\x01\x04\x10\x00\\(Dk\x1b-\x04\xdc\x1d\x07\x14\x98;\x0bS\x7f\x7f \xf9\x13\
\x04\x10@\xf9X\xbe\x00\xc9
\x14K\xc1<={\x00\x00\x00\x00IEND\xaeB`\x82'

seems different from code which created by img2py.
  
What does that mean -- "seems different"? It's exactly the same.

The img2py utility was recently updated to produce the image data in a slightly more compact and easier to deal with format. The data shown above is from the previous version of img2py, although it still works fine.

That
string is not magic. It's just the contents of the GIF file, read into
a string and printed. It's the exact same thing you'd get if you opened
the interpreter and said:
   >>> open('xxx.gif','rb').read()

As can be seen embedded in the image data header above, its actually a PNG image.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Christopher Barker wrote:

<div class="moz-text-flowed" style="font-family: -moz-fixed">Tim
Roberts wrote:

What does that mean -- "seems different"? It's exactly the same. That
string is not magic. It's just the contents of the GIF file, read into
a string and printed. It's the exact same thing you'd get if you opened
the interpreter and said:
   >>> open('xxx.gif','rb').read()

no, it's not -- it's the image read into a wxImage, then dumped in
some binary format -- I don't remember which, but it's not GIF.

You're right, his example was not a GIF. It was a PNG. Quoting:
    '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR...
However, there is no additional wrapper here. That's just a raw PNG,
dumped exactly as I quoted above.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.