{"action":"opened","issue":{"url":"https://api.github.com/repos/python-pillow/Pillow/issues/2255","repository_url":"https://api.github.com/repos/python-pillow/Pillow","labels_url":"https://api.github.com/repos/python-pillow/Pillow/issues/2255/labels{/name}","comments_url":"https://api.github.com/repos/python-pillow/Pillow/issues/2255/comments","events_url":"https://api.github.com/repos/python-pillow/Pillow/issues/2255/events","html_url":"https://github.com/python-pillow/Pillow/issues/2255","id":191427714,"number":2255,"title":"Devnagri font not working","user":{"login":"manishp11","id":15002696,"avatar_url":"https://avatars.githubusercontent.com/u/15002696?v=3","gravatar_id":"","url":"https://api.github.com/users/manishp11","html_url":"https://github.com/manishp11","followers_url":"https://api.github.com/users/manishp11/followers","following_url":"https://api.github.com/users/manishp11/following{/other_user}","gists_url":"https://api.github.com/users/manishp11/gists{/gist_id}","starred_url":"https://api.github.com/users/manishp11/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manishp11/subscriptions","organizations_url":"https://api.github.com/users/manishp11/orgs","repos_url":"https://api.github.com/users/manishp11/repos","events_url":"https://api.github.com/users/manishp11/events{/privacy}","received_events_url":"https://api.github.com/users/manishp11/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-24T03:47:17Z","updated_at":"2016-11-24T03:47:17Z","closed_at":null,"body":"###\r\n![input](https://cloud.githubusercontent.com/assets/15002696/20559418/5116fa5a-b19a-11e6-9e14-7eabb4342a28.png)\r\n\r\n### I am printing text written in devnagri unicode to jpg and png\r\n\r\n### all i can see in images in boxes.\r\n\r\n### python 2 and 3 both, with pillow pip install\r\n\r\n```\r\n# Draw (Bitmap Font) Text to Image\r\n# coding: utf-8\r\nfrom PIL import Image, ImageDraw, ImageFont\r\n\r\ndef reverseColor(r, g, b):\r\n    return (255 - r, 255 - g, 255 - b)\r\ndef grayscaleColor(r, g, b):\r\n    a = (r + g + b) / 3\r\n    return (a, a, a)\r\n\r\ntext = \"तपःस्वाध्यायनिरतं तपस्वी वाग्विदां वरम्\"\r\ntextColor = (0, 255, 0) # RGB lime\r\n#textBackgroundColor = (255, 0, 0) # RGB Red\r\ntextX = 200 # text width in pixels\r\ntextY = 50 # text height in pixels\r\ntextTopLeftX = 100\r\ntextTopLeftY = 100\r\n\r\n# create new image\r\n# imgx = 1920 # image width in pixels\r\n# imgy = 1080 # image height in pixels\r\n# image = Image.new(\"RGB\", (imgx, imgy))\r\n\r\n# load image\r\nimage = Image.open(\"input.png\")\r\n(imgx, imgy) = image.size\r\nimage = image.resize((imgx, imgy), Image.BICUBIC)\r\n\r\nfont = ImageFont.truetype(\"Devnew.ttf\", 15) # load default bitmap font\r\n(width, height) = font.getsize(text)\r\ntextImage = font.getmask(text)\r\npixels = image.load()\r\nfor y in range(imgy):\r\n    by = int(height * (y - textTopLeftY) / textY + 0.5)\r\n    if by >= 0 and by < height:\r\n        for x in range(imgx):\r\n            bx = int(width * (x - textTopLeftX) / textX + 0.5)\r\n            if bx >= 0 and bx < width:\r\n                if textImage.getpixel((bx, by)) == 0: # text background\r\n                    # pass # transparent background\r\n                    # pixels[x, y] = textBackgroundColor\r\n                    (r, g, b, a) = pixels[x, y]\r\n                    #(r, g, b) = pixels[x, y]\r\n                    #pixels[x, y] = grayscaleColor(r, g, b)\r\n                else: # text foreground\r\n                    pixels[x, y] = textColor                \r\n                    (r, g, b, a) = pixels[x, y]\r\n                    # (r, g, b) = pixels[x, y]\r\n                    # pixels[x, y] = reverseColor(r, g, b)\r\n\r\nimage.save(\"output.png\", \"PNG\")\r\n```\r\n"}}
{"actor":{"display_login":"manishp11"}}