How do I auto-resize an image to fit the length of text?

Hello. I’m working on the UI. Currently creating a chat window.
There’s one problem. As the title says, how do i auto-resize an image to fit the length of text?


The first image is current state. It’s very bad.

second image is that I want.

++

Please let me know if you have a way or tip or a good idea. Always waiting your answer.
Have a good day!

You can try getting the calculated height of the text element and resizing the parent based on that:

https://developer.playcanvas.com/en/api/pc.ElementComponent.html#calculatedHeight