3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python + ImageMagick > BMP形式の文字一覧から文字を切り出す (東雲フォントのBMP変換に対して)

Last updated at Posted at 2019-11-12
動作環境
Ubuntu 16.04 LTS
Python 3.5.2
ImageMagick 6.8.9-9 Q16 x86_64 2018-09-28

概要

  • 東雲フォント(BDF形式)をBMP形式に変換した
  • BMP形式から各文字を切り出す
    • 16x16のフォント

実装 v0.1

枠線は2ピクセル。

divide_191112.py

import subprocess as sb
import sys

# on Python 3.5.2
# Ubuntu 16.04 LTS

# cut out 16x16 bitmap fonts

BORDER_WIDTH = 2
INFILE = "shnmk16.bmp"
idx = 0
for lin in range(10):
    for col in range(32):
        idx = idx + 1
        xpos = BORDER_WIDTH + (BORDER_WIDTH + 16) * col
        ypos = BORDER_WIDTH + (BORDER_WIDTH + 16) * lin
        aform = "convert %s -crop 16x16+%d+%d wrk-%03d.bmp"
        acmd = aform % (INFILE, xpos, ypos, idx)
        print(acmd)
        sb.getoutput(acmd)

wrk-000.bmpのように文字ごとにファイルになる。
これを使ってanimated gifを作成できる。

切り出したファイル

  • wrk-148: 数値の始まり
  • wrk-158: upper case英字の始まり
  • wrk-184: lower case英字の始まり
  • wrk-210: ひらがなの始まり
  • wrk-293: カタカナの始まり

実装 v0.2

divide_191112.py
import subprocess as sb
import sys

# on Python 3.5.2
# Ubuntu 16.04 LTS

# cut out 16x16 bitmap fonts

BORDER_WIDTH = 2
INFILE = "shnmk16.bmp"
idx = 0
for lin in range(10):
    for col in range(32):
        idx = idx + 1
        xpos = BORDER_WIDTH + (BORDER_WIDTH + 16) * col
        ypos = BORDER_WIDTH + (BORDER_WIDTH + 16) * lin
        # aform = "convert %s -crop 16x16+%d+%d wrk-%03d.bmp"  # x 1
        aform = "convert %s -crop 16x16+%d+%d -resize 32x32 -channel RGB -negate wrk-%03d.bmp"  # x2 invert
        acmd = aform % (INFILE, xpos, ypos, idx)
        print(acmd)
        sb.getoutput(acmd)

3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?