diff --git a/img2irc.py b/img2irc.py
@@ -5,7 +5,7 @@
Props:
- forked idea from malcom's img2irc (https://github.com/waveplate/img2irc)
- big props to wrk (wr34k) for forking this one
- - contrast enhancement, effects, & RBG88 added by acidvegas
+ - brightness/contrast/effects & more added by acidvegas
pull request: https://github.com/ircart/scroll/pull/3
@@ -18,6 +18,7 @@ try:
except ImportError:
raise SystemExit('missing required \'pillow\' library (https://pypi.org/project/pillow/)')
+effects = ('greyscale', 'blackwhite', 'invert')
palettes = {
'RGB88': [0xffffff, 0x000000, 0x00007f, 0x009300, 0xff0000, 0x7f0000, 0x9c009c, 0xfc7f00,
0xffff00, 0x00fc00, 0x009393, 0x00ffff, 0x0000fc, 0xff00ff, 0x0, 0x0,
@@ -46,14 +47,18 @@ palettes = {
0xbcbcbc, 0xe2e2e2, 0xffffff]
}
-def convert(data, max_line_len, img_width=80, palette='RGB99', enhance=False, effect=None):
+def convert(data, max_line_len, img_width=80, palette='RGB99', brightness=False, contrast=False, effect=None):
if palette not in palettes:
raise Exception('invalid palette option')
+ if effect and effect not in effects:
+ raise Exception('invalid effect option')
palette = palettes[palette]
image = Image.open(io.BytesIO(data))
del data
- if enhance:
- image = ImageEnhance.Contrast(image)
+ if birghtness:
+ image = ImageEnhance.Brightness(im).enhance(brightness)
+ if contrast:
+ image = ImageEnhance.Contrast(image).enhance(contrast)
if effect == 'greyscale':
image = image.convert("L")
elif effect == 'blackwhite':
diff --git a/scroll.py b/scroll.py
@@ -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, 'paste':True, 'png_contrast':False, 'png_palette':'RGB99', '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_brightness':0, 'png_contrast':0, 'png_effect':None, '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['png_palette'], self.settings['png_contrast'])
+ 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_brightness'], self.settings['png_contrast'], self.settings['png_effect'])
except Exception as ex:
await self.irc_error(chan, 'failed to convert image', ex)
else:
@@ -311,14 +311,14 @@ class Bot():
setting = args[2]
option = args[3]
if setting in self.settings:
- if setting in ('flood','lines','msg','png_width','results'):
+ if setting in ('flood','lines','msg','png_brightness','png_contrast','png_width','results'):
try:
option = float(option)
self.settings[setting] = option
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 in ('paste', 'png_contrast'):
+ elif setting == 'paste':
if option == 'on':
self.settings[setting] = True
await self.sendmsg(chan, color('OK', light_green))
@@ -327,6 +327,8 @@ class Bot():
await self.sendmsg(chan, color('OK', light_green))
else:
await self.irc_error(chan, 'invalid option', 'must be on or off')
+ elif setting == 'png_effect' and option in ('false','none','off','0'):
+ self.settings[setting] = None
else:
self.settings[setting] = option
await self.sendmsg(chan, color('OK', light_green))
| |