mirror of
git://git.acid.vegas/scroll.git
synced 2024-11-07 08:46:45 +00:00
Fully implemented contrast, brightness, & effects for .ascii img
This commit is contained in:
parent
8fbc870f58
commit
03cd2c405b
26
README.md
26
README.md
@ -31,17 +31,21 @@ Designed to be portable, there is no API key needed, no local art files needed,
|
||||
**NOTE**: The sync & settings commands are admin only! `admin` is a *nick!user@host* mask defined in [scroll.py](https://github.com/ircart/scroll/blob/master/scroll.py)
|
||||
|
||||
## Settings
|
||||
| Setting | Description |
|
||||
| -------------- | ---------------------------------------------------------------------------- |
|
||||
| `flood` | delay between each command |
|
||||
| `ignore` | directories to ignore in `.ascii random` *(comma seperated list, no spaces)* |
|
||||
| `lines` | max lines outside of #scroll |
|
||||
| `msg` | delay between each message sent |
|
||||
| `paste` | enable or disable `.ascii play` |
|
||||
| `png_contrast` | enable or disable contrast enhancement for `.ascii img` output |
|
||||
| `png_palette` | palette option for `.ascii img` output *(RGB99 or RGB88)* |
|
||||
| `png_width` | maximum width for `.ascii img` output |
|
||||
| `results` | max results to return in `.ascii search` |
|
||||
| Setting | Type | Default | Description |
|
||||
| ---------------- | ------------ | ------------------------------------------------------------------------------ |
|
||||
| `flood` | int or float | delay between each command |
|
||||
| `ignore` | str | directories to ignore in `.ascii random` *(comma seperated list, no spaces)* |
|
||||
| `lines` | int | max lines outside of #scroll |
|
||||
| `msg` | int or float | delay between each message sent |
|
||||
| `paste` | boolean | enable or disable `.ascii play` |
|
||||
| `png_brightness` | int or float | increase or decrease brightness for `.ascii img` output |
|
||||
| `png_contrast` | int or float | increase or decrease contrast for `.ascii img` output |
|
||||
| `png_effect` | str | change the effect for `.ascii img` output *(greyscale, blackwhite, or invert)* |
|
||||
| `png_palette` | str | palette option for `.ascii img` output *(RGB99 or RGB88)* |
|
||||
| `png_width` | int | maximum width for `.ascii img` output |
|
||||
| `results` | int | max results to return in `.ascii search` |
|
||||
|
||||
**NOTE**: Setting **0** to `png_brightness`, `png_contrast`, or `png_effect` will disable the setting.
|
||||
|
||||
## Preview
|
||||
|
||||
|
13
img2irc.py
13
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':
|
||||
|
10
scroll.py
10
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))
|
||||
|
Loading…
Reference in New Issue
Block a user