# How to get image bytes?

**URL:** <https://community.plotly.com/t/how-to-get-image-bytes/2182>\
**Category:** 📊 Plotly Python\
**Created:** [September 23, 2016, 11:07am UTC](https://community.plotly.com/t/how-to-get-image-bytes/2182 "2016-09-23T11:07:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomas](https://avatars.discourse-cdn.com/v4/letter/t/439d5e/32.png) [@tomas](https://community.plotly.com/u/tomas)\
**Post date:** [September 23, 2016, 11:07am UTC](https://community.plotly.com/t/how-to-get-image-bytes/2182/1 "2016-09-23T11:07:33Z")

</div>

How to get png image bytes directly from Figure. Without saving the image locally or on the website.

---

<div class="post-metadata">

**Author:** ![Adam](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/adam/32/23418_2.png) [@Adam](https://community.plotly.com/u/Adam)\
**Post date:** [September 23, 2016, 2:58pm UTC](https://community.plotly.com/t/how-to-get-image-bytes/2182/2 "2016-09-23T14:58:06Z")

</div>

Hi there,

What you can do is take your `fig` which is essentially a dictionary of all your data, then…

- execute `image_hex = py.image.get(fig, format='png', height=fig['layout']['height'], width=fig['layout']['width'])`  
which uses `py.image.get()` to return the string of the png

-next make sure you `import sys` and execute `sys.getsizeof(image_hex)` which should give you the byte count

I tested this with a small scatterplot image which gave me a byte count of 4023, whereas clicking _get info_ on the downloaded image gave me 4150, but the difference looks statistically insignificant.

---

<div class="post-metadata">

**Author:** ![tomas](https://avatars.discourse-cdn.com/v4/letter/t/439d5e/32.png) [@tomas](https://community.plotly.com/u/tomas)\
**Post date:** [September 23, 2016, 5:35pm UTC](https://community.plotly.com/t/how-to-get-image-bytes/2182/3 "2016-09-23T17:35:19Z")

</div>

> [@Adam](#):
>
> py.image.get()

Thanks! this is what I needed. But why does it still call the API? I don’t store anything on Plotly’s cloud. Is there a way to do the same thing with plotly.offline?

---

<div class="post-metadata">

**Author:** ![Adam](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/adam/32/23418_2.png) [@Adam](https://community.plotly.com/u/Adam)\
**Post date:** [October 5, 2016, 8:12pm UTC](https://community.plotly.com/t/how-to-get-image-bytes/2182/4 "2016-10-05T20:12:55Z")

</div>

I believe the short answer to that is that you are still making a `GET` request, which is one of the ways you can interact with the server. It still counts for something, as does a `POST` request, which is more the bread and butter type of request.

Yes you can use py.image.get() in offline mode. I just tried it and it works.

Sorry for the late reply as well. Hope all this helps.
