<div dir="ltr"><div>[ps: Sent by error]</div><div><br></div><div>So it's complaining about trying to concatenate a string and a 'bytes' object</div><div><br></div><div>Do you know if/how to solve it?</div><div>

<br></div><div>Fra</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/9/2 Francesco Montesano <span dir="ltr"><<a href="mailto:franz.bergesund@gmail.com" target="_blank">franz.bergesund@gmail.com</a>></span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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 class="im"><div><br></div><div>TypeError: Can't convert 'bytes' object to str implicitly</div><div><br></div></div><div>b'iVBORw0KGgoAAAANS</div>


</div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">2013/9/2 Zoltán Vörös <span dir="ltr"><<a 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>
    <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><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 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 href="mailto:IPython-dev@scipy.org" target="_blank">IPython-dev@scipy.org</a>
<a 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 href="mailto:IPython-dev@scipy.org" target="_blank">IPython-dev@scipy.org</a><br>
            <a 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 href="mailto:IPython-dev@scipy.org" target="_blank">IPython-dev@scipy.org</a>
<a 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 href="mailto:IPython-dev@scipy.org" target="_blank">IPython-dev@scipy.org</a><br>
<a 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>
</div></div></blockquote></div><br></div>