omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    How to use text in ImageDraw

    Pythonista
    3
    4
    2410
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • upwart
      upwart last edited by

      I want use PIL to create my own picture, including texts.
      I can draw the string, but don't know how to use another font or change the size.

      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by

        If this is for use in a scene.Scene then check out https://gist.github.com/cclauss/6532692 which contains a line:

        (imageName, imageSize) = scene.render_text(inFontName, font_name=inFontName, font_size=64)
        

        Or you can try a more PIL oriented solution like: http://stackoverflow.com/questions/16373425/add-text-on-image-using-pil

        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by

          Also check out the Meme Generator script: http://ipad.appstorm.net/how-to/utilities/pythonista-101-python-wrangling

          1 Reply Last reply Reply Quote 0
          • omz
            omz last edited by

            Here's a simple example of using ImageDraw with a custom font:

            import Image, ImageDraw, ImageFont
            
            img = Image.new('RGBA', (210, 90), 'white')
            draw = ImageDraw.Draw(img)
            font = ImageFont.truetype('Chalkduster', 72)
            draw.text((0, 0), 'Hello', fill='blue', font=font)
            
            img.show()
            

            You can access a list of available fonts from the [+] button (iPad), or by using the "Insert…" menu item (iPhone).

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors