<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Hi Francesco,<br>
    <br>
    I have tried your code in python 2.7, and I don't encounter the
    problem that you describe. However, it seems that there are some
    complications in python 3. See this thread:
    <a class="moz-txt-link-freetext" href="http://stackoverflow.com/questions/16740188/base64-b64encode-error">http://stackoverflow.com/questions/16740188/base64-b64encode-error</a><br>
    <br>
    I hope this helps,<br>
    <br>
    Zoltán<br>
    <br>
    <div class="moz-cite-prefix">On 02/09/13 17:14, Francesco Montesano
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAOCdBKJwFaA7TwHM2-h-Thq9fdC3EgzqjZxa2MW-aVPSAhRfBw@mail.gmail.com"
      type="cite">
      <div dir="ltr">Dear Zoltan,
        <div><br>
        </div>
        <div>I've split the line with the append</div>
        <div><br>
        </div>
        <div>
          <div>            fig_base64 = base64.b64encode(f.read())  #
            this works: so file read and encoded without problems</div>
          <div>            full_html = 'data:image/png;base64,' +
            fig_base64   # error TypeError: Can't convert 'bytes' object
            to str implicitly</div>
          <div>            pngs.append(full_html)</div>
        </div>
        <div><br>
        </div>
        <div>Now if I try to print(fig_base64) before the second line I
          get:</div>
        <div>
          <div><br>
          </div>
          <div>TypeError: Can't convert 'bytes' object to str implicitly</div>
          <div><br>
          </div>
          <div>b'iVBORw0KGgoAAAANS</div>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
      </div>
      <div class="gmail_extra"><br>
        <br>
        <div class="gmail_quote">2013/9/2 Zoltán Vörös <span dir="ltr"><<a
              moz-do-not-send="true" href="mailto:zvoros@gmail.com"
              target="_blank">zvoros@gmail.com</a>></span><br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div text="#000000" bgcolor="#FFFFFF"> <br>
              <div>Hi Francesco,<br>
              </div>
              <div class="im">
                <blockquote type="cite">
                  <div dir="ltr"><br>
                    <div>    import base64<br>
                    </div>
                    <div>    pngs = []</div>
                    <div>
                      <div>    for fn in images:  # loop over the input
                        file names </div>
                      <div>        with open(fn, "rb") as f:</div>
                      <div>           
                        pngs.append('data:image/png;base64,' +
                        base64.b64encode(f.read()))</div>
                    </div>
                    <div><br>
                    </div>
                    <div>But I get the following error: on the last
                      line:</div>
                    <div>TypeError: Can't convert 'bytes' object to str
                      implicitly<br>
                    </div>
                    <div><br>
                    </div>
                    <div>Is there a way to disable table lines in HTML?</div>
                  </div>
                </blockquote>
              </div>
              From this, it seems to me that you encounter the problem
              on the png-to-base64 conversion. Is that correct? Because
              afterwards the image is encoded in base64, so it's not
              binary anymore, and I don't see why html should fail at
              that point. But if it is an error in b64encode, then you
              probably don't have a valid input file.<br>
              <br>
              Cheers,<br>
              Zoltán
              <div>
                <div class="h5"><br>
                  <blockquote type="cite">
                    <div class="gmail_extra"><br>
                      <br>
                      <div class="gmail_quote">2013/9/2 Zoltán Vörös <span
                          dir="ltr"><<a moz-do-not-send="true"
                            href="mailto:zvoros@gmail.com"
                            target="_blank">zvoros@gmail.com</a>></span><br>
                        <blockquote class="gmail_quote" style="margin:0
                          0 0 .8ex;border-left:1px #ccc
                          solid;padding-left:1ex">
                          <div text="#000000" bgcolor="#FFFFFF"> Hi
                            Francesco,<br>
                            <br>
                            It might be a hack, but this works:<br>
                            <br>
                            with open("roche1.png", "rb") as image_file:<br>
                                im1 = 'data:image/png;base64,' +
                            base64.b64encode(image_file.read())<br>
                            <br>
                            with open("roche2.png", "rb") as image_file:<br>
                                im2 = 'data:image/png;base64,' +
                            base64.b64encode(image_file.read())<br>
                            <br>
                            s = """<table><br>
                            <tr><br>
                            <th><img src="%s"/></th><br>
                            <th><img src="%s"/></th><br>
                            </tr></table>"""%(im1, im2)<br>
                            t=HTML(s)<br>
                            display(t)<br>
                            <br>
                            <br>
                            Cheers,<br>
                            Zoltán
                            <div>
                              <div><br>
                                <br>
                                <div>On 02/09/13 15:32, Francesco
                                  Montesano wrote:<br>
                                </div>
                              </div>
                            </div>
                            <blockquote type="cite">
                              <div>
                                <div>
                                  <div dir="ltr">Dear List,
                                    <div><br>
                                    </div>
                                    <div>I have a script that produces
                                      some image and I'm creating a
                                      notebook for testing/logging.</div>
                                    <div><br>
                                    </div>
                                    <div>For comparison reasons, I would
                                      like to load to images in a cell
                                      and show them side by side.</div>
                                    <div><br>
                                    </div>
                                    <blockquote style="margin:0px 0px
                                      0px 40px;border:none;padding:0px">
                                      <div>from IPython.display import
                                        Image</div>
                                      <div>
                                        <div>constr =
                                          Image(filename="fig1.png")</div>
                                      </div>
                                      <div>
                                        <div>sigma =
                                          Image(filename="fig2.png")</div>
                                      </div>
                                      <div>
                                        <div>display(constr, sigma)</div>
                                      </div>
                                    </blockquote>
                                    <div><br>
                                    </div>
                                    <div>put the figures one after the
                                      other. I've tried to play with the
                                      width keyword, but that does not
                                      help.</div>
                                    <div><br>
                                    </div>
                                    <div>Making an HTML table with the
                                      output of "Image" does not work (I
                                      don't know if I should add "of
                                      course")</div>
                                    <div><br>
                                    </div>
                                    <div>
                                      <div>s = """<table></div>
                                      <div><tr></div>
                                      <div><th>{f1}</th></div>
                                      <div><th>{f2}</th></div>
                                      <div></tr>""".format(f1=constr,
                                        f2=sigma)</div>
                                      <div>t=HTML(s)</div>
                                      <div>display(t)</div>
                                    </div>
                                    <div><br>
                                    </div>
                                    <div>Is there any way to do what I
                                      want directly in the notebook? (I
                                      guess that there is some python
                                      library to do it, but I think that
                                      the notebook should be able to do
                                      it)</div>
                                    <div><br>
                                    </div>
                                    <div>Cheers,</div>
                                    <div><br>
                                    </div>
                                    <div>Fra</div>
                                  </div>
                                  <br>
                                  <fieldset></fieldset>
                                  <br>
                                </div>
                              </div>
                              <pre>_______________________________________________
IPython-dev mailing list
<a moz-do-not-send="true" href="mailto:IPython-dev@scipy.org" target="_blank">IPython-dev@scipy.org</a>
<a moz-do-not-send="true" href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a>
</pre>
                            </blockquote>
                            <br>
                          </div>
                          <br>
_______________________________________________<br>
                          IPython-dev mailing list<br>
                          <a moz-do-not-send="true"
                            href="mailto:IPython-dev@scipy.org"
                            target="_blank">IPython-dev@scipy.org</a><br>
                          <a moz-do-not-send="true"
                            href="http://mail.scipy.org/mailman/listinfo/ipython-dev"
                            target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
                          <br>
                        </blockquote>
                      </div>
                      <br>
                    </div>
                    <br>
                    <fieldset></fieldset>
                    <br>
                    <pre>_______________________________________________
IPython-dev mailing list
<a moz-do-not-send="true" href="mailto:IPython-dev@scipy.org" target="_blank">IPython-dev@scipy.org</a>
<a moz-do-not-send="true" href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a>
</pre>
                  </blockquote>
                  <br>
                </div>
              </div>
            </div>
            <br>
            _______________________________________________<br>
            IPython-dev mailing list<br>
            <a moz-do-not-send="true"
              href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
            <a moz-do-not-send="true"
              href="http://mail.scipy.org/mailman/listinfo/ipython-dev"
              target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
            <br>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
IPython-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a>
<a class="moz-txt-link-freetext" href="http://mail.scipy.org/mailman/listinfo/ipython-dev">http://mail.scipy.org/mailman/listinfo/ipython-dev</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>