Python + ImageMagick> Cut out characters from the BMP format character list (for Shinonome font BMP conversion)

Operating environment


Ubuntu 16.04 LTS
Python 3.5.2
ImageMagick 6.8.9-9 Q16 x86_64 2018-09-28

Overview

--Converted Shinonome font (BDF format) to BMP format --Cut out each character from BMP format --16x16 font

Implementation v0.1

The border is 2 pixels.

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)

It becomes a file for each character like wrk-000.bmp. You can use it to create animated gifs.

Cut out file

--wrk-148: The beginning of the number --wrk-158: upper case Beginning of letters --wrk-184: lower case Beginning of letters --wrk-210: The beginning of hiragana --wrk-293: The beginning of katakana

Implementation v0.2

--From 16x16 to 32x32 -Resize image with imagemagick by @ tukiyo3 --Thank you for the information. --Invert black and white ――Because the camera image was bad - Invert colors with ImageMagick

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)

Recommended Posts

Python + ImageMagick> Cut out characters from the BMP format character list (for Shinonome font BMP conversion)
Search for synonyms from the word list (csv) using Python Japanese WordNet
# 5 [python3] Extract characters from a character string
[Python] matplotlib: Format the diagram for your dissertation
Call Polly from the AWS SDK for Python