# Convert a base64 string of a jpeg to a texture or surface

**URL:** <https://discourse.libcinder.org/t/convert-a-base64-string-of-a-jpeg-to-a-texture-or-surface/413>\
**Category:** Using Cinder\
**Created:** [November 25, 2016, 11:22pm UTC](https://discourse.libcinder.org/t/convert-a-base64-string-of-a-jpeg-to-a-texture-or-surface/413 "2016-11-25T23:22:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brucelane](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/brucelane/32/541_2.png) [@brucelane](https://discourse.libcinder.org/u/brucelane)\
**Post date:** [November 25, 2016, 11:22pm UTC](https://discourse.libcinder.org/t/convert-a-base64-string-of-a-jpeg-to-a-texture-or-surface/413/1 "2016-11-25T23:22:48Z")

</div>

Hi embers,  
I receive from a websocket server a jpeg from a canvas on a web page:  
`var imgData = canvas.toDataURL("image/jpeg"); window.socket.emit('canvas', imgData);`

In my Cinder app, the message is received as a string, see screen capture below:

 ![](https://canada1.discourse-cdn.com/flex030/uploads/libcinder/original/1X/1e64eff065f4cfb4027be2bc817089ea4b396189.JPG)

How can I convert this string to a texture?  
Thank you for any hint.

---

<div class="post-metadata">

**Author:** ![paul.houx](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/paul.houx/32/31_2.png) [@paul.houx](https://discourse.libcinder.org/u/paul.houx)\
**Post date:** [November 26, 2016, 6:23am UTC](https://discourse.libcinder.org/t/convert-a-base64-string-of-a-jpeg-to-a-texture-or-surface/413/2 "2016-11-26T06:23:00Z")

</div>

Hi,

use Cinder’s [base64](https://github.com/cinder/Cinder/search?utf8=%E2%9C%93&q=base64) functions to convert the data to a JPEG file again, then use `loadImage` to load it from memory.

-Paul

---

<div class="post-metadata">

**Author:** ![brucelane](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/brucelane/32/541_2.png) [@brucelane](https://discourse.libcinder.org/u/brucelane)\
**Post date:** [November 27, 2016, 9:45pm UTC](https://discourse.libcinder.org/t/convert-a-base64-string-of-a-jpeg-to-a-texture-or-surface/413/3 "2016-11-27T21:45:10Z")

</div>

thank you @paul.houx it worked!

[Texture sharing between html canvas and Cinder](https://youtu.be/5wYJHCMc4IM)
