[Python] Add Text on Image using PIL

Discussão em 'Python' iniciado por Stack, Agosto 22, 2025.

  1. Stack

    Stack Membro Participativo

    I have an application that loads an Image and when the user clicks it, a text area appears for this Image (using jquery), where user can write some text on the Image. Which should be added on Image.

    After doing some research on it, I figured that PIL (Python Imaging Library ) can help me do this. So I tried couple of examples to see how it works and I managed to write text on an image. But I think there is some difference when I try it using Python Shell and in web environment. I mean the text on the textarea is very big in px. How can I achieve the same size of text when using PIL as the one on the textarea?

    The text is Multiline. How can i make it multiline in image also, using PIL?

    Is there a better way than using PIL? I am not entirely sure, If this is the best implementation.

    html:

    <img src="images/test.jpg"/>


    its the image being edited

    var count = 0;
    $('textarea').autogrow();
    $('img').click(function(){
    count = count + 1;
    if (count > 1){
    $(this).after('<textarea />');
    $('textarea').focus();
    }
    });


    the jquery to add the textarea. Also the text area is position:absolute and fixed size.

    Should i place it inside a form so i can get coordinates of textarea on image? I want to write text on image when user clicks and save it on the image.

    Continue reading...

Compartilhe esta Página