{
  "id": 127938,
  "title": "how to display graphemes correctly",
  "url": "/competitions/bengaliai-cv19/discussion/127938",
  "author_name": "",
  "post_date": "2020-01-27T20:59:24.386104900Z",
  "votes": 14,
  "comment_count": 3,
  "views": 0,
  "content": "<p>I noticed in the kernel <a href=\"https://www.kaggle.com/kaushal2896/bengali-graphemes-starter-eda-multi-output-cnn\">https://www.kaggle.com/kaushal2896/bengali-graphemes-starter-eda-multi-output-cnn</a>, that the graphemes aren't displaying properly using PIL. For example জ্জ্ব is displayed as:</p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3331121%2Fc6d8a697622cd753234966ea15ff8eb5%2FScreen%20Shot%202020-01-27%20at%2012.50.54%20PM.png?generation=1580158277008880&amp;alt=media\" alt=\"\"></p>\n\n<p>This is because PIL doesn't know how to combine the unicode pieces of Abugida scripts to form a coherent character, so it just displays them left to right.</p>\n\n<p>To fix this problem, you need to install libraqm. Since this library is a pain to install, here is the following code that I found worked for me on kernel:</p>\n\n<p><code>\n!apt-get install -y libfreetype6-dev libharfbuzz-dev libfribidi-dev gtk-doc-tools\n!wget -O raqm-0.7.0.tar.gz https://raw.githubusercontent.com/python-pillow/pillow-depends/master/raqm-0.7.0.tar.gz\n!tar -xzvf /kaggle/working/raqm-0.7.0.tar.gz\n!cd /kaggle/working/raqm-0.7.0/ &amp;&amp; ./configure --prefix=/usr &amp;&amp; make -j4 &amp;&amp; make -j4 install\n</code></p>\n\n<p>then using the code from the kernel:</p>\n\n<p>```\nimport PIL.Image as Image, PIL.ImageDraw as ImageDraw, PIL.ImageFont as ImageFont</p>\n\n<p>HEIGHT = 236\nWIDTH = 236</p>\n\n<p>def image_from_char(char):\n    image = Image.new('RGB', (WIDTH, HEIGHT))\n    draw = ImageDraw.Draw(image)\n    myfont = ImageFont.truetype('/kaggle/input/kalpurush-fonts/kalpurush-2.ttf', 120)\n    w, h = draw.textsize(char, font=myfont)\n    draw.text(((WIDTH - w) / 2,(HEIGHT - h) / 3), char, font=myfont)</p>\n\n<pre><code>return image\n</code></pre>\n\n<p>```</p>\n\n<p>We get the following output:</p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3331121%2Fc388cceff0e961a814a0c7cf4ed7c2b0%2FScreen%20Shot%202020-01-27%20at%2012.56.03%20PM.png?generation=1580158614340724&amp;alt=media\" alt=\"\"></p>",
  "messages": [
    {
      "id": "730749",
      "postDate": "01/27/2020 20:59:24",
      "content": "<p>I noticed in the kernel <a href=\"https://www.kaggle.com/kaushal2896/bengali-graphemes-starter-eda-multi-output-cnn\">https://www.kaggle.com/kaushal2896/bengali-graphemes-starter-eda-multi-output-cnn</a>, that the graphemes aren't displaying properly using PIL. For example জ্জ্ব is displayed as:</p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3331121%2Fc6d8a697622cd753234966ea15ff8eb5%2FScreen%20Shot%202020-01-27%20at%2012.50.54%20PM.png?generation=1580158277008880&amp;alt=media\" alt=\"\"></p>\n\n<p>This is because PIL doesn't know how to combine the unicode pieces of Abugida scripts to form a coherent character, so it just displays them left to right.</p>\n\n<p>To fix this problem, you need to install libraqm. Since this library is a pain to install, here is the following code that I found worked for me on kernel:</p>\n\n<p><code>\n!apt-get install -y libfreetype6-dev libharfbuzz-dev libfribidi-dev gtk-doc-tools\n!wget -O raqm-0.7.0.tar.gz https://raw.githubusercontent.com/python-pillow/pillow-depends/master/raqm-0.7.0.tar.gz\n!tar -xzvf /kaggle/working/raqm-0.7.0.tar.gz\n!cd /kaggle/working/raqm-0.7.0/ &amp;&amp; ./configure --prefix=/usr &amp;&amp; make -j4 &amp;&amp; make -j4 install\n</code></p>\n\n<p>then using the code from the kernel:</p>\n\n<p>```\nimport PIL.Image as Image, PIL.ImageDraw as ImageDraw, PIL.ImageFont as ImageFont</p>\n\n<p>HEIGHT = 236\nWIDTH = 236</p>\n\n<p>def image_from_char(char):\n    image = Image.new('RGB', (WIDTH, HEIGHT))\n    draw = ImageDraw.Draw(image)\n    myfont = ImageFont.truetype('/kaggle/input/kalpurush-fonts/kalpurush-2.ttf', 120)\n    w, h = draw.textsize(char, font=myfont)\n    draw.text(((WIDTH - w) / 2,(HEIGHT - h) / 3), char, font=myfont)</p>\n\n<pre><code>return image\n</code></pre>\n\n<p>```</p>\n\n<p>We get the following output:</p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3331121%2Fc388cceff0e961a814a0c7cf4ed7c2b0%2FScreen%20Shot%202020-01-27%20at%2012.56.03%20PM.png?generation=1580158614340724&amp;alt=media\" alt=\"\"></p>",
      "rawMarkdown": "I noticed in the kernel https://www.kaggle.com/kaushal2896/bengali-graphemes-starter-eda-multi-output-cnn, that the graphemes aren't displaying properly using PIL. For example জ্জ্ব is displayed as:\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3331121%2Fc6d8a697622cd753234966ea15ff8eb5%2FScreen%20Shot%202020-01-27%20at%2012.50.54%20PM.png?generation=1580158277008880&amp;alt=media)\n\nThis is because PIL doesn't know how to combine the unicode pieces of Abugida scripts to form a coherent character, so it just displays them left to right.\n\nTo fix this problem, you need to install libraqm. Since this library is a pain to install, here is the following code that I found worked for me on kernel:\n\n```\n!apt-get install -y libfreetype6-dev libharfbuzz-dev libfribidi-dev gtk-doc-tools\n!wget -O raqm-0.7.0.tar.gz https://raw.githubusercontent.com/python-pillow/pillow-depends/master/raqm-0.7.0.tar.gz\n!tar -xzvf /kaggle/working/raqm-0.7.0.tar.gz\n!cd /kaggle/working/raqm-0.7.0/ &amp;&amp; ./configure --prefix=/usr &amp;&amp; make -j4 &amp;&amp; make -j4 install\n```\n\nthen using the code from the kernel:\n\n```\nimport PIL.Image as Image, PIL.ImageDraw as ImageDraw, PIL.ImageFont as ImageFont\n\nHEIGHT = 236\nWIDTH = 236\n\ndef image_from_char(char):\n    image = Image.new('RGB', (WIDTH, HEIGHT))\n    draw = ImageDraw.Draw(image)\n    myfont = ImageFont.truetype('/kaggle/input/kalpurush-fonts/kalpurush-2.ttf', 120)\n    w, h = draw.textsize(char, font=myfont)\n    draw.text(((WIDTH - w) / 2,(HEIGHT - h) / 3), char, font=myfont)\n\n    return image\n```\n\nWe get the following output:\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3331121%2Fc388cceff0e961a814a0c7cf4ed7c2b0%2FScreen%20Shot%202020-01-27%20at%2012.56.03%20PM.png?generation=1580158614340724&amp;alt=media)",
      "votes": null
    },
    {
      "id": "730875",
      "postDate": "01/28/2020 03:37:55",
      "content": "<p><a href=\"/linainversez\">@linainversez</a>  thanks.\ni have been using this website to check the rendering: <a href=\"http://www.banglatext.com/text2image.html\">http://www.banglatext.com/text2image.html</a></p>",
      "rawMarkdown": "linainversez  thanks.\ni have been using this website to check the rendering: http://www.banglatext.com/text2image.html",
      "votes": null
    },
    {
      "id": "775492",
      "postDate": "03/16/2020 18:28:42",
      "content": "<p>damnnnnn ..this is awesome</p>",
      "rawMarkdown": "damnnnnn ..this is awesome",
      "votes": null
    },
    {
      "id": "775496",
      "postDate": "03/16/2020 18:32:31",
      "content": "<p>Good god if only I’ve read this earlier would’ve saved me a whole night of debugging Libraqm installation errors...😫</p>",
      "rawMarkdown": "Good god if only I’ve read this earlier would’ve saved me a whole night of debugging Libraqm installation errors...😫",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 730875,
      "author_name": "hengck23",
      "author_url": "",
      "post_date": "01/28/2020 03:37:55",
      "content": "<p><a href=\"/linainversez\">@linainversez</a>  thanks.\ni have been using this website to check the rendering: <a href=\"http://www.banglatext.com/text2image.html\">http://www.banglatext.com/text2image.html</a></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 775492,
      "author_name": "amanikuppili",
      "author_url": "",
      "post_date": "03/16/2020 18:28:42",
      "content": "<p>damnnnnn ..this is awesome</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 775496,
      "author_name": "roguekk007",
      "author_url": "",
      "post_date": "03/16/2020 18:32:31",
      "content": "<p>Good god if only I’ve read this earlier would’ve saved me a whole night of debugging Libraqm installation errors...😫</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "730749": "I noticed in the kernel https://www.kaggle.com/kaushal2896/bengali-graphemes-starter-eda-multi-output-cnn, that the graphemes aren't displaying properly using PIL. For example জ্জ্ব is displayed as:\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3331121%2Fc6d8a697622cd753234966ea15ff8eb5%2FScreen%20Shot%202020-01-27%20at%2012.50.54%20PM.png?generation=1580158277008880&amp;alt=media)\n\nThis is because PIL doesn't know how to combine the unicode pieces of Abugida scripts to form a coherent character, so it just displays them left to right.\n\nTo fix this problem, you need to install libraqm. Since this library is a pain to install, here is the following code that I found worked for me on kernel:\n\n```\n!apt-get install -y libfreetype6-dev libharfbuzz-dev libfribidi-dev gtk-doc-tools\n!wget -O raqm-0.7.0.tar.gz https://raw.githubusercontent.com/python-pillow/pillow-depends/master/raqm-0.7.0.tar.gz\n!tar -xzvf /kaggle/working/raqm-0.7.0.tar.gz\n!cd /kaggle/working/raqm-0.7.0/ &amp;&amp; ./configure --prefix=/usr &amp;&amp; make -j4 &amp;&amp; make -j4 install\n```\n\nthen using the code from the kernel:\n\n```\nimport PIL.Image as Image, PIL.ImageDraw as ImageDraw, PIL.ImageFont as ImageFont\n\nHEIGHT = 236\nWIDTH = 236\n\ndef image_from_char(char):\n    image = Image.new('RGB', (WIDTH, HEIGHT))\n    draw = ImageDraw.Draw(image)\n    myfont = ImageFont.truetype('/kaggle/input/kalpurush-fonts/kalpurush-2.ttf', 120)\n    w, h = draw.textsize(char, font=myfont)\n    draw.text(((WIDTH - w) / 2,(HEIGHT - h) / 3), char, font=myfont)\n\n    return image\n```\n\nWe get the following output:\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3331121%2Fc388cceff0e961a814a0c7cf4ed7c2b0%2FScreen%20Shot%202020-01-27%20at%2012.56.03%20PM.png?generation=1580158614340724&amp;alt=media)",
    "730875": "linainversez  thanks.\ni have been using this website to check the rendering: http://www.banglatext.com/text2image.html",
    "775492": "damnnnnn ..this is awesome",
    "775496": "Good god if only I’ve read this earlier would’ve saved me a whole night of debugging Libraqm installation errors...😫"
  },
  "source": "meta"
}