mirror of
https://github.com/drewcassidy/quicktex.git
synced 2024-09-13 06:37:34 +00:00
decode cleanup
This commit is contained in:
parent
156880d430
commit
8a85f5c920
@ -7,15 +7,15 @@ from pathlib import Path
|
|||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option('-f', '--flip', help="vertically flip image after converting")
|
@click.option('-f/-F', '--flip/--no-flip', default=True, show_default=True, help="Vertically flip image after converting.")
|
||||||
@click.option('-r', '--remove', help="remove input images after converting")
|
@click.option('-r', '--remove', is_flag=True, help="Remove input images after converting.")
|
||||||
@click.option('-s', '--suffix', type=str, default='', help="suffix to append to output file(s).")
|
@click.option('-s', '--suffix', type=str, default='', help="Suffix to append to output file(s). Ignored if output is a single file.")
|
||||||
@click.option('-x', '--extension',
|
@click.option('-x', '--extension',
|
||||||
type=str, default='png',
|
type=str, default='png', show_default=True,
|
||||||
help="extension to use for output. ignored if output is a single file. output filetype is deduced from this")
|
help="Extension to use for output. Ignored if output is a single file. Output filetype is deduced from this")
|
||||||
@click.option('-o', '--output',
|
@click.option('-o', '--output',
|
||||||
type=click.Path(exists=True, readable=True), default='.',
|
type=click.Path(exists=True, readable=True), default=None,
|
||||||
help="output file name or directory. If outputting to a file, input filenames must be only a single item.")
|
help="Output file name or directory. If outputting to a file, input filenames must be only a single item. By default, files are decoded in place.")
|
||||||
@click.argument('filenames',
|
@click.argument('filenames',
|
||||||
nargs=-1,
|
nargs=-1,
|
||||||
type=click.Path(exists=True, readable=True))
|
type=click.Path(exists=True, readable=True))
|
||||||
@ -23,16 +23,23 @@ def decode(flip, remove, suffix, extension, output, filenames):
|
|||||||
"""Decode an input texture file to an image"""
|
"""Decode an input texture file to an image"""
|
||||||
|
|
||||||
assert len(filenames) != 0, 'No input files provided.'
|
assert len(filenames) != 0, 'No input files provided.'
|
||||||
outpath = Path(output)
|
|
||||||
|
|
||||||
if outpath.is_file():
|
if output:
|
||||||
assert len(filenames) == 1, 'Provided an output file with multiple inputs.'
|
outpath = Path(output)
|
||||||
|
if outpath.is_file():
|
||||||
|
# decode to a file
|
||||||
|
assert len(filenames) == 1, 'Provided an output file with multiple inputs.'
|
||||||
|
|
||||||
def make_outpath(p):
|
def make_outpath(p):
|
||||||
return outpath
|
return outpath
|
||||||
|
else:
|
||||||
|
# decode to directory
|
||||||
|
def make_outpath(p):
|
||||||
|
return outpath / (p.stem + suffix + '.' + extension)
|
||||||
else:
|
else:
|
||||||
|
# decode in place
|
||||||
def make_outpath(p):
|
def make_outpath(p):
|
||||||
return outpath / (p.stem + suffix + '.' + extension)
|
return p.with_name(p.stem + suffix + '.' + extension)
|
||||||
|
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
filepath = Path(filename)
|
filepath = Path(filename)
|
||||||
@ -43,4 +50,11 @@ def decode(flip, remove, suffix, extension, output, filenames):
|
|||||||
|
|
||||||
ddsfile = dds.read(filepath)
|
ddsfile = dds.read(filepath)
|
||||||
image = ddsfile.decode()
|
image = ddsfile.decode()
|
||||||
|
|
||||||
|
if flip:
|
||||||
|
image = image.transpose(Image.FLIP_TOP_BOTTOM)
|
||||||
|
|
||||||
image.save(outpath)
|
image.save(outpath)
|
||||||
|
|
||||||
|
if remove:
|
||||||
|
os.remove(filepath)
|
||||||
|
Loading…
Reference in New Issue
Block a user