dylanaraps / pywal

🎨 Generate and change color-schemes on the fly.
MIT License
8.37k stars 326 forks source link

[feature request] Support for additional color generation backends. #212

Closed kotajacob closed 6 years ago

kotajacob commented 6 years ago

This idea may be a rather large request depending on how colors are "picked" from the image in pywal. (Haven't quite had time to dig around yet, but I will do so shortly) Also this feature might be beyond what you'd like the scope of pywal to be and if so no worries, but I think it might be worth looking into as I'm sure many users would find it quite helpful.

On reddit the other day /u/deviantfero was announcing having released a new version of wpgtk and several users were wondering about if he was thinking about adding support for generating the colors with gvcci, colorthief, or any of the other wallpaper color generator tools. He thought (and I heavily agree) that it might be better to actually implement that feature into pywal instead.

I was thinking if something like that was added it might looks something like this new command line option. --backend (default) pywal or gvcci or colorthief or art or whatever Now to actually implement that I suppose there's a few different methods. Use the individual color generation programs as optional dependencies and collect the colors from their output. Or the more elegant solution of reading the color generator code in the other programs and re-implementing them as features in the pywal code.

If you'd be open to any of the above solutions or even the feature at all I'd be more than happy to work on a pr.

dylanaraps commented 6 years ago

I’ll start work on making pywal’s default backend modular so we can easily support other backends.

I’ll also look into adding support for additional user created backends. No promises on this one though.

deviantfero commented 6 years ago

If I might input here, I think colorthief would be really simple to implement.

dylanaraps commented 6 years ago

Added initial colorthief (https://github.com/fengsp/color-thief-py) support in #213 .

Any other backends I should add? (I can't get gvcci working on my system)

deviantfero commented 6 years ago

I think that is the simplest one to add, it could even eliminate the imagemagick dependency if it were good enough generating colors by itself, and you could delegate colorgeneration fully to colorthief.

https://pypi.python.org/pypi/colorz/1.0.2

this could be another candidate, but it is still k-means, this is what wpgtk used in the past, when it was only a python 2 script.

http://charlesleifer.com/blog/using-python-and-k-means-to-find-the-dominant-colors-in-images/

it generated better results most of the time when it came to colors.

kotajacob commented 6 years ago

There's a nice little tool simply called colors here which uses k-means clustering and gets pretty a pretty fine selection. I heard about it in one of z3bra's blog posts here. Another probably simple one is art by gawlk, although I think it might not generate a full 16 colors so that could be a problem.

Honestly though I think the having just support for color-thief is already very good. I imagine once users learn about this feature there will be issues and or pr's for new backends. For now though this is really great.

dylanaraps commented 6 years ago

art is just wal. Have a look at the source code, they use nearly identical imagemagick commands.

I've added support for Colorz so we now have 3 working backends. Each backend generates a distinct style of colors which is really nice. The new backends are dark theme only for the time being (I'll get around to adding light theme support. I just want to clean things up first)

deviantfero commented 6 years ago

absolutely great!

dylanaraps commented 6 years ago

I've added support for a total of 4 more color backends.

The dependencies are all "optional". pywal will display an error message (instead of crashing) if you select a backend and don't have it installed.

I've also made pywal more modular in the process. The pywal backend is now implemented the same as the others. Adding new backends is as easy as adding a new file to the backends dir.

Note: pywal does make some modifications to the outputs from the other theme generators. This is to improve brightness, contrast, saturation etc. The changes are also made so that the colors fit the pywal format so they work out of the box with the vim theme etc.

I still need to add tests, fix the existing ones and possibly work on a feature that allows user created backends (unsure about this one)

A new release will be made once #200 is also completed. If there are anymore suggestions or design ideas let me know now so I can implement them before I finalize everything.