Generate base16 color schemes from images
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
3.0 KiB

  1. * Auto Base16 Theme
  2. [[./images/Example4.jpg]]
  3. ** What it does
  4. This script generates a [[https://github.com/chriskempson/base16][base16]] color theme intended for code syntax highlighting from a source image.
  5. This means you can have *beautiful, readable* themes which match your desktop background without having to do any work.
  6. I currently only have a template for Emacs, but it should work for any editor which supports base16. If you create a template for your format/editor of choice, please feel free to create a pull request adding that template so others can benefit from it.
  7. ** Setup
  8. This script relies on [[https://github.com/thefryscorer/schemer2][schemer2]] to choose colors from images. It then takes the output of schemer2 and selects colors which fit the base16 format. Make sure you have Go installed, then install schemer2:
  9. : go get github.com/thefryscorer/schemer2
  10. AutoBase16Theme.py requires Python 3.
  11. ** How to Use
  12. Run the following command, replacing ~your image~ with the image you want the theme's colors to be pulled from:
  13. : schemer2 -format img::colors -in [your image] -out colors.txt && python3 AutoBase16Theme.py [your template] [your output file]
  14. *** Explanation
  15. - ~schemer2~ generates the color palette from the source image and outputs a list of color values to ~colors.txt~.
  16. - We then run AutoBase16Theme.py (which loads ~colors.txt~ by default). AutoBase16Theme.py selects from these color values (and modifies them, if necessary) such that a good theme is created. It loads ~your template~ and writes the final theme to ~your output file~.
  17. For example, I have an image "wallpaper.jpg" and I want an [[https://github.com/belak/base16-emacs][Emacs base16]] theme to be generated:
  18. : schemer2 -format img::colors -in wallpaper.jpg -out colors.txt && python3 AutoBase16Theme.py emacs-base16-theme-template.el base16-my-wallpaper-theme.el
  19. I can then copy ~base16-my-wallpaper-theme.el~ into my Emacs base16 directory and evaluate it, then select it as a theme.
  20. *** Additional Arguments
  21. Note that running
  22. : python3 AutoBase16Theme.py
  23. will output help with argument descriptions.
  24. *** Emacs convenience function
  25. Here's an Emacs Lisp setup for making it easier to create new themes. You'll need to customize it with your own paths.
  26. #+BEGIN_SRC lisp
  27. (setq macoy-auto-theme-schemer2-bin "~/go/bin/schemer2.exe")
  28. (setq macoy-auto-theme-script-dir "~/auto-base16-theme")
  29. (setq macoy-auto-theme-output-file
  30. "~/AppData/Roaming/.emacs.d/elpa/base16-theme-20190413.1637/base16-my-auto-theme.el")
  31. (defun macoy-generate-auto-theme ()
  32. "Create a base16 auto-theme using AutoBase16Theme.py based on the image selected."
  33. (interactive)
  34. (let ((default-directory macoy-auto-theme-script-dir))
  35. (compile
  36. (format "%s -format img::colors -in \"%s\" -out colors.txt && C:/Python_34/python.exe AutoBase16Theme.py emacs-base16-theme-template.el %s"
  37. macoy-auto-theme-schemer2-bin (read-file-name "Image: ") macoy-auto-theme-output-file))))
  38. #+END_SRC
  39. ** Example results
  40. [[./images/Example1.jpg]]
  41. [[./images/Example2.jpg]]
  42. [[./images/Example3.jpg]]