mirror of
git://git.acid.vegas/scroll.git
synced 2024-11-07 08:46:45 +00:00
Added contrast enhancement option
This commit is contained in:
parent
098373555e
commit
b0e8a15f0e
@ -13,7 +13,7 @@ pull request: https://github.com/ircart/scroll/pull/3
|
||||
import io
|
||||
|
||||
try:
|
||||
from PIL import Image
|
||||
from PIL import Image, ImageEnhance
|
||||
except ImportError:
|
||||
raise SystemExit('missing required \'pillow\' library (https://pypi.org/project/pillow/)')
|
||||
|
||||
@ -45,11 +45,13 @@ palettes = {
|
||||
0xbcbcbc, 0xe2e2e2, 0xffffff]
|
||||
}
|
||||
|
||||
def convert(data, max_line_len, img_width=80, palette='RGB99'):
|
||||
def convert(data, max_line_len, img_width=80, palette='RGB99', enhance=False):
|
||||
if palette not in palettes:
|
||||
raise Exception('invalid palette option')
|
||||
palette = palettes[palette]
|
||||
image = Image.open(io.BytesIO(data))
|
||||
if enhance:
|
||||
image = ImageEnhance.Contrast(image)
|
||||
del data
|
||||
return convert_image(image, max_line_len, img_width, palette)
|
||||
|
||||
|
@ -84,7 +84,7 @@ class Bot():
|
||||
self.loops = dict()
|
||||
self.host = ''
|
||||
self.playing = False
|
||||
self.settings = {'flood':1, 'ignore':'big,birds,doc,gorf,hang,nazi,pokemon', 'lines':500, 'msg':0.03, 'palette':'RGB99', 'paste':True, 'png_width':80, 'results':25}
|
||||
self.settings = {'flood':1, 'ignore':'big,birds,doc,gorf,hang,nazi,pokemon', 'lines':500, 'msg':0.03, 'paste':True, 'png_contrast':False, 'png_palette':'RGB99', 'png_width':80, 'results':25}
|
||||
self.slow = False
|
||||
self.reader = None
|
||||
self.writer = None
|
||||
@ -256,7 +256,7 @@ class Bot():
|
||||
if url.startswith('https://') or url.startswith('http://'):
|
||||
try:
|
||||
content = get_url(url).read()
|
||||
ascii = img2irc.convert(content, 512 - len(f":{identity.nickname}!{identity.username}@{self.host} PRIVMSG {chan} :\r\n"), int(self.settings['png_width']), self.settings['palette'])
|
||||
ascii = img2irc.convert(content, 512 - len(f":{identity.nickname}!{identity.username}@{self.host} PRIVMSG {chan} :\r\n"), int(self.settings['png_width']), self.settings['png_palette'], self.settings['png_contrast'])
|
||||
except Exception as ex:
|
||||
await self.irc_error(chan, 'failed to convert image', ex)
|
||||
else:
|
||||
@ -318,7 +318,7 @@ class Bot():
|
||||
await self.sendmsg(chan, color('OK', light_green))
|
||||
except ValueError:
|
||||
await self.irc_error(chan, 'invalid option', 'must be a float or int')
|
||||
elif setting == 'paste':
|
||||
elif setting in ('paste', 'png_contrast'):
|
||||
if option == 'on':
|
||||
self.settings[setting] = True
|
||||
await self.sendmsg(chan, color('OK', light_green))
|
||||
|
Loading…
Reference in New Issue
Block a user