Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images with alpha channel break kmeans and wallfix #60

Open
coxley opened this issue Jul 31, 2017 · 1 comment
Open

Images with alpha channel break kmeans and wallfix #60

coxley opened this issue Jul 31, 2017 · 1 comment

Comments

@coxley
Copy link

coxley commented Jul 31, 2017

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


@s-ol s-ol changed the title Both kmeans and writing image broken Images with alpha channel break kmeans and wallfix Aug 1, 2017
@s-ol
Copy link
Owner

s-ol commented Aug 1, 2017

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants