RichTextLabel add_image() adding image to end

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By I reject all deals

I have pre-defined content in a RichTextLabel and I want to update an image that’s part of that content. But problem is my image is not on disk. With this code I can add image:

var image = Image.new()
var error = image.load_png_from_buffer(my_image)
var texture = ImageTexture.new()
texture.create_from_image(image)
$RichTextLabel.add_image(texture)

But problem is its adding image to end of my text. But I dont want it. Somewhere in my RichTextLabel I have an img tag and I want to add image on it. Not end of file. Is there is a way to do it?

I’m curious to see what other input you get by reasking the question, but to repeat a few things I mentioned in the original question.

  • One way to insert the images anywhere you want would be to manage a bbcode string yourself. That way, you can use standard string functions to insert, remove, or substitute content (including image references) as necessary. Once you have a finished bbcode string, just insert into your RichTextLabel control.
  • AFAIK, to insert an image into a RichTextLabel, you have to provide either a resource reference or a disk path to the image. If there’s a way to insert an in-memory image, I’m unaware of it. But, as I said in the OP, why not simply store your images in a temp folder, reference their paths in your bbcode string, and clean up the temp image folder when you’re done?

jgodfrey | 2023-06-13 22:34

Yes this is also way but when I tried to open an image (not in my godot project folder) its not opening and it wants an import file for image

I reject all deals | 2023-06-14 16:17

Hmmm… Yeah, in the example I provided in the other post, I hadn’t intended for the image I loaded to be in the project folder. However, I now see that it was, and that if it’s outside of the project, it does indeed fail. So, you’re right… :frowning:

jgodfrey | 2023-06-14 19:24

So how we can solve it?

I reject all deals | 2023-06-14 20:07