Skip to content

Commit

Permalink
Allow specifying output directory for image conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
tzarc committed Mar 9, 2021
1 parent 7c97cce commit 88d23bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lib/python/qmk/cli/painter/convert_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def render_source(format, palette, image_data, width, height, subs):


@cli.argument('-i', '--input', required=True, help='Specify input graphic file.')
@cli.argument('-o', '--output', default='', help='Specify output directory. Defaults to same directory as input.')
@cli.argument('-f', '--format', required=True, help='Output format, valid types: %s' % (', '.join(qmk.painter.valid_formats.keys())))
@cli.subcommand('Converts an input image to something QMK understands')
def painter_convert_graphics(cli):
Expand All @@ -154,6 +155,11 @@ def painter_convert_graphics(cli):
cli.print_usage()
return False

# Work out the output directory
if len(cli.args.output) == 0:
cli.args.output = cli.args.input.parent
cli.args.output = qmk.path.normpath(cli.args.output)

sane_name = re.sub(r"[^a-zA-Z0-9]", "_", cli.args.input.stem)

format = qmk.painter.valid_formats[cli.args.format]
Expand Down Expand Up @@ -183,13 +189,13 @@ def painter_convert_graphics(cli):
header_text = qmk.painter.clean_output(render_header(format, subs))
source_text = qmk.painter.clean_output(render_source(format, palette, image_data, width, height, subs))

header_file = cli.args.input.parent / (cli.args.input.stem + ".h")
header_file = cli.args.output / (cli.args.input.stem + ".h")
with open(header_file, 'w') as header:
print(f"Writing {header_file}...")
header.write(header_text)
header.close()

source_file = cli.args.input.parent / (cli.args.input.stem + ".c")
source_file = cli.args.output / (cli.args.input.stem + ".c")
with open(source_file, 'w') as source:
print(f"Writing {source_file}...")
source.write(source_text)
Expand Down
10 changes: 8 additions & 2 deletions lib/python/qmk/cli/painter/make_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def painter_make_font_image(cli):


@cli.argument('-i', '--input', help='Specify input graphic file.')
@cli.argument('-o', '--output', default='', help='Specify output directory. Defaults to same directory as input.')
@cli.argument('-n', '--no-ascii', arg_only=True, action='store_true', help='Disables output of the full ASCII character set (0x20..0x7F), exporting only the glyphs specified.')
@cli.argument('-u', '--unicode-glyphs', default='', help='Also generate the specified unicode glyphs.')
@cli.argument('-f', '--format', required=True, help='Output format, valid types: %s' % (', '.join(qmk.painter.valid_formats.keys())))
Expand All @@ -287,6 +288,11 @@ def painter_convert_font_image(cli):
cli.args.input = qmk.path.normpath(cli.args.input)
img = Image.open(cli.args.input)

# Work out the output directory
if len(cli.args.output) == 0:
cli.args.output = cli.args.input.parent
cli.args.output = qmk.path.normpath(cli.args.output)

# Work out the geometry
(width, height) = img.size

Expand Down Expand Up @@ -347,13 +353,13 @@ def painter_convert_font_image(cli):
source_text = qmk.painter.clean_output(render_source(format, palette, glyph_data, subs))

# Render out the text files
header_file = cli.args.input.parent / (cli.args.input.stem + ".h")
header_file = cli.args.output / (cli.args.input.stem + ".h")
with codecs.open(header_file, 'w', 'utf-8-sig') as header:
print(f"Writing {header_file}...")
header.write(header_text)
header.close()

source_file = cli.args.input.parent / (cli.args.input.stem + ".c")
source_file = cli.args.output / (cli.args.input.stem + ".c")
with codecs.open(source_file, 'w', 'utf-8-sig') as source:
print(f"Writing {source_file}...")
source.write(source_text)
Expand Down

0 comments on commit 88d23bb

Please sign in to comment.