scroll

- irc bot to play ascii art
git clone git://git.acid.vegas/scroll.git
Log | Files | Refs | Archive | README | LICENSE

commit b0e8a15f0ee5c7a18296b183a63b87fd5f62695a
parent 098373555e1788578815ba6cb4e47a658e0e2fbe
Author: acidvegas <acid.vegas@acid.vegas>
Date: Wed, 28 Jun 2023 15:04:14 -0400

Added contrast enhancement option

Diffstat:
Mimg2irc.py | 6++++--
Mscroll.py | 6+++---

2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/img2irc.py b/img2irc.py
@@ -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)
 
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, '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))