Updated a lot of text output
This commit is contained in:
parent
65a9b1cf37
commit
9d062c48a3
28
lid
28
lid
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import sys
|
import sys
|
||||||
import os.path
|
import os, os.path
|
||||||
|
|
||||||
# Default dithering: 4 level ordered dither
|
# Default dithering: 4 level ordered dither
|
||||||
def ordered_dither_4(r):
|
def ordered_dither_4(r):
|
||||||
|
@ -24,7 +24,7 @@ def ordered_dither_4(r):
|
||||||
counter = 1
|
counter = 1
|
||||||
last_percent_val = 0
|
last_percent_val = 0
|
||||||
last_hash_val = 0
|
last_hash_val = 0
|
||||||
print("Ordered dither: 4 level")
|
print("Dither method: ordered (4 levels)\033[?25l")
|
||||||
for row in range(0, height):
|
for row in range(0, height):
|
||||||
for col in range(0, width):
|
for col in range(0, width):
|
||||||
dotrow = 1 if row % 2 else 0
|
dotrow = 1 if row % 2 else 0
|
||||||
|
@ -40,7 +40,7 @@ def ordered_dither_4(r):
|
||||||
last_hash_val = new_hash_val
|
last_hash_val = new_hash_val
|
||||||
|
|
||||||
new.save("{}.{}".format(r["out"], r["-f"]), r["-f"].upper(), optimize=True, quality=r["-q"])
|
new.save("{}.{}".format(r["out"], r["-f"]), r["-f"].upper(), optimize=True, quality=r["-q"])
|
||||||
print("\033[20C\nfinished\033[?25h")
|
print("\033[20C\nFinished! ~ {}/{}.{}\033[?25h".format(os.getcwd(), r["out"], r["-f"].lower()))
|
||||||
|
|
||||||
# 9 level ordered dither
|
# 9 level ordered dither
|
||||||
def ordered_dither_9(r):
|
def ordered_dither_9(r):
|
||||||
|
@ -59,7 +59,7 @@ def ordered_dither_9(r):
|
||||||
counter = 1
|
counter = 1
|
||||||
last_percent_val = 0
|
last_percent_val = 0
|
||||||
last_hash_val = 0
|
last_hash_val = 0
|
||||||
print("Ordered dither: 9 level")
|
print("Dither method: ordered (9 levels)\033[?25l")
|
||||||
for row in range(0, height):
|
for row in range(0, height):
|
||||||
for col in range(0, width):
|
for col in range(0, width):
|
||||||
if not row % 3:
|
if not row % 3:
|
||||||
|
@ -86,7 +86,7 @@ def ordered_dither_9(r):
|
||||||
last_hash_val = new_hash_val
|
last_hash_val = new_hash_val
|
||||||
|
|
||||||
new.save("{}.{}".format(r["out"], r["-f"]), r["-f"].upper(), optimize=True, quality=r["-q"])
|
new.save("{}.{}".format(r["out"], r["-f"]), r["-f"].upper(), optimize=True, quality=r["-q"])
|
||||||
print("\033[20C\nfinished\033[?25h")
|
print("\033[20C\nFinished! ~ {}/{}.{}\033[?25h".format(os.getcwd(), r["out"], r["-f"].lower()))
|
||||||
|
|
||||||
# Alternate dither mode
|
# Alternate dither mode
|
||||||
def error_dither(r):
|
def error_dither(r):
|
||||||
|
@ -100,7 +100,7 @@ def error_dither(r):
|
||||||
counter = 1
|
counter = 1
|
||||||
last_percent_val = 0
|
last_percent_val = 0
|
||||||
last_hash_val = 0
|
last_hash_val = 0
|
||||||
print("Error diffusion dither")
|
print("Dither method: error diffusion\033[?25l")
|
||||||
for row in range(0, height):
|
for row in range(0, height):
|
||||||
for col in range(0, width):
|
for col in range(0, width):
|
||||||
newpixels[col, row] = update_error(im, i, row, col)
|
newpixels[col, row] = update_error(im, i, row, col)
|
||||||
|
@ -113,7 +113,7 @@ def error_dither(r):
|
||||||
last_hash_val = new_hash_val
|
last_hash_val = new_hash_val
|
||||||
|
|
||||||
new.save("{}.{}".format(r["out"], r["-f"]), r["-f"].upper(), optimize=True, quality=r["-q"])
|
new.save("{}.{}".format(r["out"], r["-f"]), r["-f"].upper(), optimize=True, quality=r["-q"])
|
||||||
print("\033[20C\nfinished\033[?25h")
|
print("\033[20C\nFinished! ~ {}/{}.{}\033[?25h".format(os.getcwd(), r["out"], r["-f"].lower()))
|
||||||
|
|
||||||
|
|
||||||
def update_error(im, i, r, c):
|
def update_error(im, i, r, c):
|
||||||
|
@ -168,9 +168,9 @@ def display_help():
|
||||||
lid [option]... [infile] [outfile]
|
lid [option]... [infile] [outfile]
|
||||||
|
|
||||||
options:
|
options:
|
||||||
-f output format. defaults to: png
|
-f output format. defaults to: png (recommended)
|
||||||
-q image quality. defaults to: 90. only has effect on png/jpg
|
|
||||||
-m dither mode. defaults to: o4. other options: e, o9
|
-m dither mode. defaults to: o4. other options: e, o9
|
||||||
|
-q image quality. defaults to: 90. only has effect on png/jpg
|
||||||
|
|
||||||
arguments:
|
arguments:
|
||||||
infile path to a valid image file on your system
|
infile path to a valid image file on your system
|
||||||
|
@ -178,6 +178,14 @@ def display_help():
|
||||||
|
|
||||||
example usage:
|
example usage:
|
||||||
lid -f jpeg -q 75 -m e ~/my_picture.png my_dithered_picture
|
lid -f jpeg -q 75 -m e ~/my_picture.png my_dithered_picture
|
||||||
|
|
||||||
|
notes:
|
||||||
|
it is highly recommended that users output their files as PNG. the file
|
||||||
|
size will be significantly smaller than jpeg and the quality in most
|
||||||
|
cases will be about the same.
|
||||||
|
|
||||||
|
the quality flag mostly seems to effect jpegs and does not do a whole
|
||||||
|
heap to PNG files, but play around with it as mileage may vary.
|
||||||
"""
|
"""
|
||||||
print(helptext)
|
print(helptext)
|
||||||
|
|
||||||
|
@ -218,7 +226,7 @@ def parse_input():
|
||||||
else:
|
else:
|
||||||
argmap["path"] = x
|
argmap["path"] = x
|
||||||
|
|
||||||
if not argmap["-f"] in ["jpeg", "jpg", "png", "gif", None]:
|
if not argmap["-f"].lower() in ["jpeg", "jpg", "png", "gif"]:
|
||||||
print("lid error: invalid format requested with -f flag. Options: jpeg, png, gif. Defaults to png")
|
print("lid error: invalid format requested with -f flag. Options: jpeg, png, gif. Defaults to png")
|
||||||
return None
|
return None
|
||||||
elif argmap["-f"] == "jpg":
|
elif argmap["-f"] == "jpg":
|
||||||
|
|
Loading…
Reference in New Issue