{"id":158,"date":"2019-05-17T12:50:44","date_gmt":"2019-05-17T03:50:44","guid":{"rendered":"https:\/\/blog.hgrs.me\/?p=158"},"modified":"2019-05-19T14:10:02","modified_gmt":"2019-05-19T05:10:02","slug":"pillowpil%e3%81%a7opentype%e3%83%95%e3%82%a3%e3%83%bc%e3%83%81%e3%83%a3%e3%83%bc%e3%82%92%e8%a8%ad%e5%ae%9a%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/blog.hgrs.me\/archives\/158.html","title":{"rendered":"Pillow(PIL)\u3067OpenType\u30d5\u30a3\u30fc\u30c1\u30e3\u30fc\u3092\u8a2d\u5b9a\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"

\u306f\u3058\u3081\u306b<\/h2>\n

Python\u3067\u753b\u50cf\u3092\u4f5c\u308a\u305f\u3044\u969b\u306b\u4fbf\u5229\u306b\u4f7f\u3048\u308b\u306e\u304cPillow\u3067\u3059\u3002<\/p>\n

\u9700\u8981\u304c\u3042\u308b\u306e\u304b\u77e5\u308a\u307e\u305b\u3093\u304c\u3001\u305d\u306ePillow\u306e\u6a5f\u80fd\u3092\u5229\u7528\u3057\u3066OpenType\u30d5\u30a3\u30fc\u30c1\u30e3\u30fc\u3092\u8a2d\u5b9a\u3057\u3001\u7dba\u9e97\u306b\u6587\u5b57\u3092\u7d44\u3093\u3067\u307f\u307e\u3057\u3087\u3046\uff01<\/p>\n

Pillow<\/a>\u3068\u306f<\/h2>\n

PIL\uff08Python Imaging Library\uff09\u306e\u30d5\u30a9\u30fc\u30af\u3067\u3059\u3002<\/p>\n

Python\u3067\u753b\u50cf\u3092\u6271\u3046\u969b\u306b\u4f7f\u308f\u308c\u307e\u3059\u3002Python\u3067\u753b\u50cf\u3092\u6271\u3046\u3068\u304d\u306b\u50d5\u306f\u3060\u3044\u305f\u3044OpenCV\u304b\u3053\u306ePillow\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n

OpenType\u30d5\u30a3\u30fc\u30c1\u30e3\u30fc<\/a>\u3068\u306f<\/h2>\n

\u308f\u304b\u308a\u3084\u3059\u3044\u3068\u3053\u308d\u3067\u3044\u3046\u3068\u30ab\u30fc\u30cb\u30f3\u30b0\u3084\u30ea\u30ac\u30c1\u30e3\uff08\u4eca\u56de\u8a66\u3059\u306e\u3082\u3053\u306e2\u3064\u3067\u3059\uff09\u3067\u3059\u3002\u30ab\u30fc\u30cb\u30f3\u30b0\u306f\u6587\u5b57\u3068\u6587\u5b57\u306e\u9593\u9694\u306e\u3053\u3068\u3067\u3001\u305d\u308c\u3092\u81ea\u52d5\u3067\u8abf\u6574\u3057\u3066\u304f\u308c\u308b\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\u3002\u30ea\u30ac\u30c1\u30e3\u306f\u7279\u5b9a\u306e\u6587\u5b57\u304c\u7d9a\u304f\u969b\u306b\u5b57\u306e\u5f62\u3092\u5909\u3048\u308b\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n

\u3069\u3061\u3089\u3082\u3001\u5f8c\u3067\u51fa\u3066\u304f\u308b\u5b9f\u969b\u306e\u51fa\u529b\u753b\u50cf\u3092\u898b\u308c\u3070\u308f\u304b\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n

\u524d\u6e96\u5099<\/h2>\n

Pillow\u3067OpenType\u30d5\u30a3\u30fc\u30c1\u30e3\u30fc\u3092\u5229\u7528\u3059\u308b\u306b\u306f\u3001libraqm<\/code>\u3068\u3044\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u3042\u3089\u304b\u3058\u3081\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304a\u304b\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002<\/p>\n

\u3053\u3053\u3067\u306fmacOS\u3092\u4f8b\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u65b9\u6cd5\u3092\u8aac\u660e\u3057\u307e\u3059\u3002\u307b\u304b\u306eOS\u306e\u65b9\u306f\u3053\u3061\u3089<\/a>\u306e\u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u53c2\u8003\u306b\u9032\u3081\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n

\u4f9d\u5b58\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n

brew<\/code>\u3092\u5229\u7528\u3057\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u306e\u3067\u3001\u5165\u308c\u3066\u306a\u3044\u4eba\u306f\u5165\u308c\u307e\u3057\u3087\u3046\u3002<\/p>\n

$ brew install freetype harfbuzz fribidi gtk-doc<\/code><\/pre>\n

libraqm\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n

\u307e\u305alibraqm\u306e\u30ea\u30dd\u30b8\u30c8\u30ea\u306e\u30ea\u30ea\u30fc\u30b9\u30da\u30fc\u30b8<\/a>\u304b\u3089\u6700\u65b0\u7248\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3001\u89e3\u51cd\u3057\u307e\u3059\u3002
\n\"libraqm\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\"
\n\u30bf\u30fc\u30df\u30ca\u30eb\u3067\u3001\u305d\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u79fb\u52d5\u3057\u307e\u3057\u3087\u3046\u3002\u305d\u3053\u3067\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n

$ .\/configure\n$ make\n$ make install<\/code><\/pre>\n

\u3053\u308c\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u5b8c\u4e86\u3067\u3059\u3002Pillow\u3067OpenType\u30d5\u30a3\u30fc\u30c1\u30e3\u30fc\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

\u3067\u306f\u4f7f\u3044\u65b9\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n

\u5b9f\u969b\u306b\u4f7f\u3063\u3066\u307f\u308b<\/h2>\n

\u5b9f\u969b\u306e\u30b3\u30fc\u30c9\u304c\u3053\u3061\u3089\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

from PIL import Image, ImageDraw, ImageFont\n\n# \u767d\u3044\u30ad\u30e3\u30f3\u30d0\u30b9\u3092\u7528\u610f\nimage = Image.new('L', (1200, 630), 255)\n# \u63cf\u753b\u7528\u610f\ndraw = ImageDraw.Draw(image)\n\n# TrueType\/OpenType\u30d5\u30a9\u30f3\u30c8\u306e\u8aad\u307f\u8fbc\u307f\ntruetype_font = ImageFont.truetype('mplus-1p-regular.ttf', size=200)\n# \u30d5\u30a9\u30f3\u30c8\u306e\u30bb\u30c3\u30c8\ndraw.font = truetype_font\n# \u30c6\u30ad\u30b9\u30c8\u63cf\u753b\uff08OpenType\u30d5\u30a3\u30fc\u30c1\u30e3\u30fc\u3092\u6709\u52b9\uff09\ndraw.text((0, 0), 'fi, AW, ON', fill=0, features=['liga', 'kern'])\n# \u30c6\u30ad\u30b9\u30c8\u63cf\u753b\uff08OpenType\u30d5\u30a3\u30fc\u30c1\u30e3\u30fc\u3092\u7121\u52b9: \u30de\u30a4\u30ca\u30b9\u3092\u5148\u982d\u306b\u5165\u308c\u308b\uff09\ndraw.text((0, 300), 'fi, AW, OFF', fill=0, features=['-liga', '-kern'])\n\n# \u753b\u50cf\u306e\u4fdd\u5b58\nimage.save('out.png')<\/code><\/pre>\n

\u3053\u306e\u30b3\u30fc\u30c9\u3067\u4fdd\u5b58\u3055\u308c\u308b\u753b\u50cf\u304c\u3053\u3061\u3089\u306b\u306a\u308a\u307e\u3059\u3002
\n\"Pillow\u3067OpenType\u30d5\u30a3\u30fc\u30c1\u30e3\u30fc\"
\n\u7dba\u9e97\u306b\u51fa\u529b\u3055\u308c\u307e\u3057\u305f\u306d\uff01<\/p>\n

ImageDraw.text()<\/code>\u306b\u304a\u3044\u3066features<\/code>\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u5229\u7528\u3059\u308bOpenType\u30d5\u30a3\u30fc\u30c1\u30e3\u30fc\u3092\u6307\u5b9a\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001\u3053\u3053\u3067\u6307\u5b9a\u3059\u308b\u6587\u5b57\u5217\u306fOpenType\u306e\u4ed5\u69d8\u66f8\u306b\u3042\u308b\u30ea\u30b9\u30c8<\/a>\u304b\u3089\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n

\u4ed6\u306b\u3082\u8272\u3005\u306a\u3082\u306e\u3092\u8a66\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n

\u304a\u308f\u308a\u306b<\/h2>\n

\u304b\u306a\u308a\u30de\u30cb\u30a2\u30c3\u30af\u306a\u5185\u5bb9\u3067\u3057\u305f\u304c\u50d5\u306f\u4f55\u304b\u3068\u6587\u5b57\u753b\u50cf\u3092\u4f5c\u308b\u6a5f\u4f1a\u304c\u591a\u3044\u306e\u3067\u3001\u304a\u3055\u3089\u3044\u307e\u3067\u306b\u307e\u3068\u3081\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n

\u3053\u308c\u304b\u3089\u3082\u6587\u5b57\u306b\u95a2\u3059\u308b\u8a18\u4e8b\u304c\u5897\u3048\u308b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u304a\u4ed8\u304d\u5408\u3044\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u306f\u3058\u3081\u306b Python\u3067\u753b\u50cf\u3092\u4f5c\u308a\u305f\u3044\u969b\u306b\u4fbf\u5229\u306b\u4f7f\u3048\u308b\u306e\u304cPillow\u3067\u3059\u3002 \u9700\u8981\u304c\u3042\u308b\u306e\u304b\u77e5\u308a\u307e\u305b…<\/p>\n","protected":false},"author":1,"featured_media":159,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[25,14,21],"_links":{"self":[{"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/posts\/158"}],"collection":[{"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/comments?post=158"}],"version-history":[{"count":7,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/posts\/158\/revisions"}],"predecessor-version":[{"id":260,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/posts\/158\/revisions\/260"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/media\/159"}],"wp:attachment":[{"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/media?parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/categories?post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/tags?post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}