themer
themer copied to clipboard
Images with alpha channel break kmeans and wallfix
If kmeans
is installed from pypi, it's broken because themer
passes (r, g, b, a)
to it where it only expects (r, g, b)
. See the below exception
$ themer generate color-squares downloads/JmTbnY8.png
# example value ((31, 124, 141, 255), 1)
Traceback (most recent call last):
File "/home/coxley/.local/bin/themer", line 323, in <module>
generate(color_file, config, template_dir, theme_name, options.bright)
File "/home/coxley/.local/bin/themer", line 170, in generate
colors = parse.read()
File "/home/coxley/.local/lib/python3.6/site-packages/themer/parsers/__init__.py", line 159, in read
colors = self.get_dominant_colors()
File "/home/coxley/.local/lib/python3.6/site-packages/themer/parsers/__init__.py", line 142, in get_dominant_colors
rgbs = kmeans.kmeans(points, self.k)
File "/home/coxley/.local/lib/python3.6/site-packages/kmeans/__init__.py", line 104, in kmeans
tolerance=tolerance, max_iterations=max_iterations)
File "/home/coxley/.local/lib/python3.6/site-packages/kmeans/__init__.py", line 61, in _kmeans
(r, g, b), count = center
ValueError: too many values to unpack (expected 3)
Removing kmeans/manually patching fixes this however then it gets stopped writing
Falling back to python kmeans implementation.
Consider installing 'kmeans' from PyPI for much faster image sampling
Activate now? yN y
Traceback (most recent call last):
File "/home/coxley/.local/lib/python3.6/site-packages/PIL/JpegImagePlugin.py", line 602, in _save
rawmode = RAWMODE[im.mode]
KeyError: 'RGBA'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/coxley/.local/bin/themer", line 336, in <module>
activate(theme_name)
File "/home/coxley/.local/bin/themer", line 157, in activate
act.activate()
File "/home/coxley/.local/lib/python3.6/site-packages/themer/activators/wallfix.py", line 90, in activate
self.crop_wallpaper(wallpaper)
File "/home/coxley/.local/lib/python3.6/site-packages/themer/activators/wallfix.py", line 76, in crop_wallpaper
cropped.save(dest_jpg, 'JPEG', quality=100)
File "/home/coxley/.local/lib/python3.6/site-packages/PIL/Image.py", line 1893, in save
save_handler(self, fp, filename)
File "/home/coxley/.local/lib/python3.6/site-packages/PIL/JpegImagePlugin.py", line 604, in _save
raise IOError("cannot write mode %s as JPEG" % im.mode)
OSError: cannot write mode RGBA as JPEG
quick workaround is convert -flatten wallpaper.png wallpaper-flattened.png
real alpha handling beyond just ignoring that channel I think will not be implemented ever (but the wallfix'd image should contain it again)