img: improve alpha handling, edit ramp

This commit is contained in:
Gordon Shumway 2019-05-05 07:06:23 -04:00 committed by GitHub
parent 6e018ff7d9
commit d8948f613e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 4 deletions

View File

@ -312,13 +312,13 @@ class ASCII(callbacks.Plugin):
else:
cols = 100
if 'invert' in optlist:
gscale = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'."
gscale = "$@B%&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|(){}[]?-_+~<>i!lI;:\"^`'."
elif 'chars' in optlist:
gscale = optlist.get('chars')
if not gscale.strip():
gscale = '\xa0'
else:
gscale = ".'`^\",:;Il!i><~+_-?][}{1)(|\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$"
gscale = ".'`^\":;Il!i><~+_-?][}{)(|\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&%B@$"
if 'delay' in optlist:
delay = optlist.get('delay')
else:
@ -343,6 +343,10 @@ class ASCII(callbacks.Plugin):
# open image and convert to grayscale
image = Image.open(filename).convert('L')
image2 = Image.open(filename)
if image2.mode == 'RGBA':
image2 = Image.alpha_composite(Image.new("RGBA", image2.size), image2)
if image2.mode != 'RGB':
image2 = image2.convert('RGB')
try:
os.remove(filename)
except:
@ -358,8 +362,6 @@ class ASCII(callbacks.Plugin):
rows = int(H/h)
image = ImageOps.autocontrast(image)
image = image.resize((cols, rows), Image.LANCZOS)
image2 = image2.convert('RGBA')
image2 = image2.convert('RGB')
image2 = ImageOps.autocontrast(image2)
image2 = image2.resize((cols, rows), Image.LANCZOS)
if 'dither' in optlist: