# Create image from SQL text

**URL:** <https://forum.inductiveautomation.com/t/create-image-from-sql-text/73642>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [May 12, 2023, 10:41am UTC](https://forum.inductiveautomation.com/t/create-image-from-sql-text/73642 "2023-05-12T10:41:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matabufalez](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matabufalez/32/42267_2.png) [@Matabufalez](https://forum.inductiveautomation.com/u/Matabufalez)\
**Post date:** [May 12, 2023, 10:41am UTC](https://forum.inductiveautomation.com/t/create-image-from-sql-text/73642/1 "2023-05-12T10:41:11Z")

</div>

Hello!  
I would like to generate an image from a text string stored in the SQL database.

We are currently doing it with another application, but I would like to migrate that into Perspective.  
This is one example. Each cell represents one position from the stored value.  
i.e. 1=blue  
2=green  
3=yellow  
4= purple

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/0/30fd86352d27aaee46c09a6c5711ff10260ed2d6.png)

So, How could I do that? I have not seen this question in any thread, and with the default tools I am not able to represent it.  
The strings's lenght are not always the same.

Thank you!  
Thank you!

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 12, 2023, 11:48am UTC](https://forum.inductiveautomation.com/t/create-image-from-sql-text/73642/2 "2023-05-12T11:48:56Z")

</div>

Does it have to be an image? The example you posted looks like a table with equal sized rows/columns and background cell color configured based on data from your db. Could that work?

Also you should post an example of the data in your database. Does your data record the coordinates with the color or is your data literally just a string like `blue,blue,blue,green,...`

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [May 12, 2023, 11:52am UTC](https://forum.inductiveautomation.com/t/create-image-from-sql-text/73642/3 "2023-05-12T11:52:04Z")

</div>

Probably a heatmap would do.

> **[Ignition Exchange](https://inductiveautomation.com/exchange/2127/overview)**
>
> Discover, share, and download community made Ignition resources in collaboration with your organization or the Ignition community.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/7/77f83cfbdc7e86a080620e2b31b905c3c831c22e.jpeg)

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [May 12, 2023, 12:02pm UTC](https://forum.inductiveautomation.com/t/create-image-from-sql-text/73642/4 "2023-05-12T12:02:29Z")

</div>

this might be usefull too

> [@Perspective - Best Way To Display Grid 10,000 x 384](https://forum.inductiveautomation.com/t/perspective-best-way-to-display-grid-10-000-x-384/50526/21):
>
> The pypng library is a straight port. The attached script package has the pypng (png) library along with a couple of helper functions to process the DINTs to a list of lists suitable for pypng… File size stays about 480k [test\_graphics\_2021-09-02\_1214.zip](https://forum.inductiveautomation.com/uploads/short-url/3UhwxwjgFCEf8k7HkBUxsnTQcGe.zip) (24.0 KB) import random # Randomized Sample Data sampleData = [random.randrange(0, 2\*\*32) for j in xrange(120000)] # Process the DINTs to a list of lists suitable for pypng (single-bit depth) data, width, height = graphics.dint.processData(sa…

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [May 12, 2023, 12:06pm UTC](https://forum.inductiveautomation.com/t/create-image-from-sql-text/73642/5 "2023-05-12T12:06:40Z")

</div>

I forgot about that one. I write a lot of stuff I forget about. lol.

I think we'll need a bit more information on what the output is supposed to look like with variable length input.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [May 12, 2023, 12:09pm UTC](https://forum.inductiveautomation.com/t/create-image-from-sql-text/73642/6 "2023-05-12T12:09:39Z")

</div>

took me a while to find it back, i bookmark to much stuff without adding any tittles to it xd

---

<div class="post-metadata">

**Author:** ![Matabufalez](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matabufalez/32/42267_2.png) [@Matabufalez](https://forum.inductiveautomation.com/u/Matabufalez)\
**Post date:** [May 13, 2023, 1:37pm UTC](https://forum.inductiveautomation.com/t/create-image-from-sql-text/73642/7 "2023-05-13T13:37:38Z")

</div>

> [@bkarabinchak.psi](#):
>
> Does it have to be an image? The example you posted looks like a table with equal sized rows/columns and background cell color configured based on data from your db. Could that work?
> 
> Also you should post an example of the data in your database. Does your data record the coordinates with the color or is your data literally just a string like `blue,blue,blue,green,...`

No matter what output is, but I need to get the colour map somehow, not necessary an image.  
This is an example of the stored string:  
_5\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_13\_\_2\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_1\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_5_

The underscore repreents blue, and the numbers the colour of the data.

Which one of the two solutions could be better for this application?  
Heatmap or Pypng library?
