Code Monkey home page Code Monkey logo

gvcci's Introduction

alt text

About

This project was developed as an alternative to the commonly used tool wal which was used by many in the UNIX community to extract colors from images in order to create terminal themes that matched their wallpapers.

The main flaw with wal is that it often missed smaller pops of differentiated color within an image, leaving its results monotone & uninteresting. This project aims to remedy that by using clustering algorithms on an image's colours so that small pockets of highly differentiated colours get picked up and have a shot at making it into the final colour palette.

For some examples, check out: http://fabricecastel.github.io/colors/examples.html

The project is still very much a work in progress, with background color logic in the works so that you can choose between light, dark & custom background colors. Feel free to join in the discussion via the github issues page, or the thread on /r/unixporn here

Screenshots

alt text alt text alt text alt text

Setup

This program has the following dependencies:

  • python3
  • numpy
  • scikit-learn
  • scikit-image
  • hasel
  • pystache

To setup the project and dependencies:

  1. If you don't have python3 installed, you should download it here: https://www.python.org/downloads/ (3.6.3 is the most up to date version as of the writing of this readme)
  2. Download & Extract (or clone) the source files from the github repo: https://github.com/FabriceCastel/gvcci
  3. cd into your local copy of the git repository
  4. ./install_dependencies.sh will download the required python libraries and initialize the git submodules
  5. ./gvcci.sh path/to/image.jpg to run the program

Running the program will print the generated color palette, generate an examples.html file with some previews that you can open in any web browser and a theme package in ~/.gvcci/themes/ containing the image and the filled out templates.

Options

--background [auto|light|dark|<hex>] - Defaults to auto, which can pick either a light or dark background depending on the image. The light and dark options have it pick either a light or a dark color from the image as the background, and <hex> allows you to specify a hex code to use as background color.

--template [file|directory] - Defaults to ./templates. Specify which template to use when generating the output. If your argument is a file, that template file will be used. If it's a directory, all files in that directory will be used as templates. For more information regarding templates, refer to the Templates section below.

--print-output - If enabled, will output only the filled out template(s) to stdout.

--symlink-wallpaper - If enabled, the wallpaper image will be saved as a symlink rather than as a copy of the file under ~/.gvcci/themes/.

macOS iTerm users

You're in luck because that's my setup and I've made it easy to use gvcci with it. You can run ./iterm_lazy.sh [img_path] for an easy one-step extract palette + generate iTerm profile + update iTerm profile + update wallpaper. You will need a recent version of iTerm (one that supports dynamic profiles) for this to work.

Roadmap/TODO List

  • Output a foreground color
  • Assign adequately dark color to the ANSI 'Black' color value
  • Improve background color selection for light themes
  • Fix light themes resulting in dull grey background colors
  • Improve theme bundling
  • Improve syntax colors for light themes
  • Map the generated colors to their nearest ANSI counterpart (ie. the ANSI red should be the most "red" of the generated colors etc)
  • Refactor the codebase and modularize it where appropriate
  • Add the ability to use output templates
  • Integrate theme generation and apply scripts (add params in config to apply?)
  • Generalize script? (ie. be able to request X light colors, Y dark colors and Z variants on each color)
  • Store generated color theme in ~./gvcci/themes/.../ to allow for easy reuse with other templates rather than recompute the colors every time
  • Add commandline params to specify min/max contrast levels between light and dark colours, min/max saturation values, etc

Templates

When writing a template, you have access to the following colors:

background
foreground
bold
cursor
selection
selected-text
ansi-black-normal
ansi-black-bright
ansi-red-normal
ansi-red-bright
ansi-green-normal
ansi-green-bright
ansi-yellow-normal
ansi-yellow-bright
ansi-blue-normal
ansi-blue-bright
ansi-magenta-normal
ansi-magenta-bright
ansi-cyan-normal
ansi-cyan-bright
ansi-white-normal
ansi-white-bright

For each color, you have access to the following variants:

<color>-[red|green|blue]-255 (a value for the rgb components in the [0, 255] range)
<color>-[red|green|blue]-float (a value for the rgb components in the [0, 1] range)
<color>-hex (the hex code of the color)

Here's the "hello world" of gvcci templates:

Background: {{background-hex}}
Foreground RGB: [{{foreground-red-255}}, {{foreground-green-255}}, {{foreground-blue-255}}]

If you had a pure black background with pure red foreground, this would yield

Background: #000000
Foreground RGB: [255, 0, 0]

gvcci's People

Contributors

devneal avatar fabricecastel avatar ikhatri avatar nan0s7 avatar rschmukler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gvcci's Issues

Colours are all wrong & error D:

So when I run extract.py I get the following error:
Traceback (most recent call last): File "extract.py", line 150, in <module> ansi_colors_unconstrained = pick_n_best_colors(8, improved_centers, dominant_dark, dominant_light, min_dark_contrast, min_light_contrast) File "/home/scott/Projects/gvcci/scoring.py", line 267, in pick_n_best_colors within_bounds = filter_within_bounds(hsl_colors, max_contrast_requirement) File "/home/scott/Projects/gvcci/scoring.py", line 265, in filter_within_bounds return colors[boundary_contrast(colors) >= contrast_threshold] File "/home/scott/Projects/gvcci/scoring.py", line 259, in boundary_contrast return contrast_between_boundaries(colors, dark_boundary, light_boundary, dark_min_contrast, light_min_contrast) File "/home/scott/Projects/gvcci/scoring.py", line 195, in contrast_between_boundaries dark_contrast = contrast_between_all(colors, dark_boundary) File "/home/scott/Projects/gvcci/scoring.py", line 39, in contrast_between_all rl_max = np.max(rl_a, rl_b) File "/usr/lib/python3.5/site-packages/numpy/core/fromnumeric.py", line 2272, in amax out=out, **kwargs) File "/usr/lib/python3.5/site-packages/numpy/core/_methods.py", line 26, in _amax return umr_maximum(a, axis, None, out, keepdims) TypeError: only integer scalar arrays can be converted to a scalar index

So fix that when you can. ;P

Also I have another suggestion, can you reduce the size of the repository as a whole? I assume most of the size is from the pictures and such, but in my opinion ~77 MB is a bit much for most people and their internet connections. One thing you could try is to make a repository for all of the pictures and such (or upload them to a website like imgur) so that's optional for those who want the samples and such.

iTerm Dynamic profile command /usr/local/bin/fish breaks new windows

Description

The created iTerm Dynamic profile tries to run a not existent script /usr/local/bin/fish, thus breaking the launch of a new temrinal window.
image

Steps to Reproduce

  1. Run ./iterm_lazy
  2. Set gvcci as default profile
  3. Cmd+N to open new terminal window

Expected behavior: Maybe no command to be called on dynamic profile

Actual behavior: Command gets called, pipe breaks, new terminal windows don't work

Great work so far, keep it up ๐Ÿ˜

Error using --background option

Running python3 extract.py --background "#000000" ~/Pictures/Images/Wallpapers/08.jpg yields

Traceback (most recent call last):
  File "extract.py", line 120, in <module>
    if (bg_color[2] < 0.5):
IndexError: index 2 is out of bounds for axis 0 with size 1

When I print bg_color at this point, I see array([[ 0., 0., 0.]]), so maybe it should be if (bg_color[0][2] < 0.5):?

Dependency installer

Hey,

Love what you're doing here - I always wanted a more refined version of wal and to get the specific codes and stuff from the background image.

When I ran python3 setup.py install it'd error out. There would be an issue installing each dependency except for the hasel one.

To fix this, I manually had to run the commands pip3 install numpy, and the same for cython, scikit-image and scikit-learn.

But after doing those manually the setup exited fine and was able to use the next command to extract the hex values from my chosen image.

More information about my computer; running Solus OS with the 4.13.8-28.current kernel and Python 3, version 3.5.4. If you need someone to help out or test things I'm happy to help any way I can.

Again, thanks for the awesome tool!
~ nan0s7

Moar bugs! :D

There's a spelling error when you echo the colour codes to the terminal. You spelt "background" wrong - it says "backgorund" ;P

Also it seems like extract.py doesn't output the template I use anymore. Unless you changed the command and I didn't notice....

Have a good day! :D

Plug-in support

Hey,

Sorry about making another issue so soon after the other one, but I had an idea. Ever since I found your script, I've been adapting it to feed into my secondary script which uses code from the Gogh project to automatically create a new terminal profile with the newly generated colours.

So I was wondering; to make my life easier, and for possibly anyone who wants to do a similar thing to me in the future, if we could have a "raw" output option. For example, what I am doing right now is finding the array that you use to store each hex code after all of the computation, concatenating each colour code into a long string variable, then essentially running my custom script from inside of yours.

How I would like to improve that, is in some way not to make me modify your code so it's easier to update for anyone doing any additions to your code. I could directly read the output that you print to the terminal at the end, but that is difficult and messy to do in Bash (my current scripting language). I would prefer something that doesn't need to change with each update, or something that you don't need to worry too much about when updating your code. Something like creating a small .txt file with one line containing the hex codes formatted in an easy-to-deal-with way (such as my concatenation idea (i.e. #20001e#dad6d9#53004e#94d4ad#d682bb#dddddd#36e442#06f39d#03f012#b1b1b1#86007e#aef6cb#f69fda#fcfcfc#60f76a#37ffb7#31ff3e#d6d0ca).

Then I can just read the whole file knowing that it's formatted in a way I can easily manipulate.

If you have any ideas or other plans please let me know.

Thanks for your help and code.

Set wallpaper for multiple desktops

Hello,

I've looked in the docs but I couldn't find a way to set the wallpaper for all my desktops in OSX. I think it would be a useful option.
Is it possible?

Many thanks,
Andrei

Script fails on grey-images

Description

This line throws the following error on this image:

Traceback (most recent call last):
  File "src/extract.py", line 66, in <module>
    hsl_colors = get_pixels_for_image(img_file_path)
  File "src/extract.py", line 30, in get_pixels_for_image
    img_hsl = hasel.rgb2hsl(img_rgb[:,:,0:3])
IndexError: too many indices for array

Steps to Reproduce

Run ./gvcci.sh [path_to_image]

Additional Information

The documentation for skimage.io.imread reads:

    Returns
    -------
    img_array : ndarray
        The different colour bands/channels are stored in the
        third dimension, such that a grey-image is MxN, an
        RGB-image MxNx3 and an RGBA-image MxNx4.

Which leads me to believe that the line will produce unexpected results on all grey-images and RGBA-images.

Add LICENSE, please

Hi!

Thanks for your work! I'm (probably) dropping few PRs myself (formatting main etc). Before I can do that, can you please add LICENSE file, so that the license is clear.

Also, as a side note I'm happy to contribute some more code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.