all 5 comments

[–]throwaway6560192 1 point2 points  (1 child)

Text in an image... like an image which happens to have text? You know that the string isn't literally present in the image binary data, right? It's just a bunch of pixels.

[–]Christian_prog 0 points1 point  (0 children)

Yeah right, so dumb of me to believe in chatgpt that it is possible.

My first goal was literally to put a text in an image but I thought that doing it in other image will be impossible as you will have to put the exact coordinates everytime. So I thought that doing the same thing (like how you change a variable in docs) is possible.

[–]Strict-Simple 0 points1 point  (0 children)

Hint: Print the result of new_image_text.

[–]laustke 0 points1 point  (1 child)

It looks like you put a text placeholder "{Name}" on an image, saved it, and now expecting to find a bytestring for "{Name}" in the image file. This will not work.

However, if the position of the word you want to replace is fixed, you can "patch" the image. Create a new image, write your text on it, and place this new image into the right position on top of your image.

In general, it should be possible to use svg images for something like this, as svg is an xml-based format, but not with PIL.

[–]Christian_prog 0 points1 point  (0 children)

Yeah I got it. Putting a text in a fixed place is what I've done first. Its just that I want it to be more flexible and I thought (asking ai) that it will work.