Page 1 of 3
Palleter
Posted: Wed Oct 30, 2013 10:42 pm
by rhowaldt
as boasted in some other thread, i have put my CLI where my mouth is and have created palleter, a bash script to create a color pallete from a given image. right now, for testing purposes mostly, but also because, well, maybe you want it, it will change your console theme with it immediately as well. of course there is the much superior
Console Theme Switcher to switch your console themes with a collection of stuff, and maybe there is some way to integrate this tool with that mother.
here's the script:
Code: Select all
#!/bin/bash
# takes an image and creates a color palette from it
# which gets echoed to the console.
#
# made by rhowaldt (fuck you)
#
# depends: imagemagick
PALETTE=$(convert "$1" -colors 16 -format "%c" histogram:info:)
HEXLIST=$(echo "$PALETTE" | sed 's/^.*\#\(.*\) srgb.*/\1/g')
COL=("0" "8" "1" "9" "2" "A" "3" "B" "4" "C" "5" "D" "6" "E" "7" "F");
x=0
while read line; do
echo -en "\e]P${COL[$x]}$line";
let x=x+1
done <<< "$HEXLIST"
clear
here's the image i used for testing:
- tigermonk
here's the resulting scheme:
- nice 'n pink
- tigermonk.png (10.83 KiB) Viewed 9132 times
(possible) issues: i am new to all this, and i did not take care to make sure a color resembling white is actually being used for the 'white' console color. in order to do something like this there would have to be a hex-color-check in the script that determines how close a certain color is to one of the designated ones. i do not know if this matters at all. please let me know :)
Re: Palleter
Posted: Wed Oct 30, 2013 11:33 pm
by wuxmedia
fucking awesome. *bows*
thought you'd been quiet, and for good reason.
I wouldn't worry about checking the colours being near the stated ones.
As long as they are as distinctly visible as they are on your scrot. it'd maybe worth making sure there are only unique colours.
considering the picture has no huge ranges of different colours, it did really well
If nothing else - It provides a set of colours to be tweaked.
Re: Palleter
Posted: Thu Oct 31, 2013 1:08 am
by ivanovnegro
Awesome Rho. I like it and will take it to my collection without hesitating.
Re: Palleter
Posted: Thu Oct 31, 2013 2:57 am
by DebianJoe
*applause*
Re: Palleter
Posted: Thu Oct 31, 2013 4:48 am
by machinebacon
fucking great! the pink is funny there, but i tested it on a bunch of wallpapers and it works 100% well. maybe the orange is pushed towards pink, fuck knows.
about your remark (color range) maybe this is helpful:
http://www.fmwconcepts.com/imagemagick/ ... /index.php
scroll down, down, down
Re: Palleter
Posted: Thu Oct 31, 2013 9:51 am
by GekkoP
wow! Really great effort here. Will use it next time I want to pimp my bbq.
Re: Palleter
Posted: Thu Oct 31, 2013 10:02 am
by rhowaldt
thanks guys :)
@jules: read a whole lot about dithering and whatnot, long story short, apparently IM takes an average of the colors. now, i believe because i extract 16 colors from the image, the results are relatively accurate, but of course there will still be averaging going on to some extent. this is probably why the 'pink is funny' (agreed).
interesting site. this:
http://www.fmwconcepts.com/imagemagick/ ... /index.php - is basically what i do here as well, only with 16 colors.
@DJ: i was wondering: right now i output the results directly to the console, just like your Theme Switcher. but have you given thought to users adding new themes to the switcher themselves? of course they can edit the code, which is what i did (btw, for those using the example above, i called it 'tigermonk' :) - but it might be nice to have some way to add output of Palleter to Theme Switch? lemme know what you think. of course i'd be fine with keeping both side-by-side as well, i don't care :D
Re: Palleter
Posted: Thu Oct 31, 2013 10:11 am
by DebianJoe
@Rho: I had not considered anything other than users being able to add their own themes other than just hacking in whatever they wanted. You are more than welcome to take a shot at automating that process. The switcher was kept as basic as I could make it, because I really wanted it for killx and rsi more than anything. Throw out ideas, big dog. I'll help however I can.
Re: Palleter
Posted: Thu Oct 31, 2013 1:32 pm
by dkeg
thanks for working up and sharing rho! and a great name too!
Re: Palleter
Posted: Thu Oct 31, 2013 4:19 pm
by rhowaldt
@DJ: i kinda figured that was your approach when i looked at the script. i'll think about it, but i don't wanna overcomplicate shit either. so this is fine for now :)
Re: Palleter
Posted: Sat Nov 02, 2013 8:39 am
by fog
THANK YOU.
This is awesome. My -new- favorite, must-have script, in every installation.
Thanks again MR R :)
Re: Palleter
Posted: Sat Nov 02, 2013 10:36 am
by rhowaldt
glad to have made you happy Ms F! and congrats on a beautiful wallpaper. i forget the artists' name but all her (right?) stuff is gorgeous. echoes of Mucha :)
Re: Palleter
Posted: Sat Nov 02, 2013 12:59 pm
by fog
rhowaldt wrote:glad to have made you happy Ms F! and congrats on a beautiful wallpaper. i forget the artists' name but all her (right?) stuff is gorgeous. echoes of Mucha :)
Could not agree more. Her name is
Audrey Kawasaki and her work is innocent and erotic at the same time.
ps. I'm already addicted to this script :)
Re: Palleter
Posted: Sat Nov 02, 2013 5:22 pm
by rhowaldt
^ that is a magnificent description of her work, couldn't have said it better. lovely.
thanks for the praise! it was just a simple idea but somebody had to build it. look at the script and boggle your mind on the complexity of it all! :P
Re: Palleter
Posted: Sat Nov 02, 2013 6:34 pm
by fog
I made a slightly modified version for terminator -i know... terminator? shame on me :P - and a
mini how-to (in greek, but the code is code) in my blog.
I really like this script :)
Code: Select all
#!/bin/bash
# takes an image and creates a color palette from it
# which gets echoed to the console.
#
# made by rhowaldt (fuck you)
# customized for terminator by fog
# depends: imagemagick
PALETTE=$(convert "$1" -colors 16 -format "%c" histogram:info:)
HEXLIST=$(echo "$PALETTE" | sed 's/^.*\#\(.*\) srgb.*/\1/g')
COL=("#" ":#" ":#" ":#" ":#" ":#" ":#" ":#" ":#" ":#" ":#" ":#" ":#" ":#" ":#" ":#");
x=0
while read line; do
echo -en "${COL[$x]}$line";
let x=x+1
done <<< "$HEXLIST"
clear
Re: Palleter
Posted: Sat Nov 02, 2013 7:01 pm
by xaos52
Great script.
I did not know convert could do that.
Here is a slightly modified version of the original script:
- avoiding strings holding temporary results
- replacing let with the modern version
Code: Select all
#!/bin/bash
# takes an image and creates a color palette from it
# which gets echoed to the console.
#
# made by rhowaldt (fuck you)
#
# depends: imagemagick
COL=("0" "8" "1" "9" "2" "A" "3" "B" "4" "C" "5" "D" "6" "E" "7" "F");
x=0
while read -r line; do
echo -en "\e]P${COL[$x]}$line";
x=$((x+1))
done < <(convert "$1" -colors 16 -format "%c" histogram:info: | sed 's/^.*\#\(.*\) srgb.*/\1/g')
Re: Palleter
Posted: Sun Nov 03, 2013 2:33 am
by machinebacon
Is the space intentional in the last line between the two < ?
Re: Palleter
Posted: Sun Nov 03, 2013 10:36 am
by xaos52
Yes,it is.
The first one is a simple redirection, the second one part of the <() syntax.
See
http://mywiki.wooledge.org/BashGuide/In ... bstitution for the latter.
Re: Palleter
Posted: Sun Nov 03, 2013 1:12 pm
by rhowaldt
@fog: cool, Titan just asked me whether you had to use a certain terminal emulator to make it work, and really i only thought about using it for framebuffer/tty... so this is great! thanks :)
@xaos: ah i see, nice... this goes beyond my current bash skills :)
btw, i did know about 'let' being oldschool, but i find the syntax somewhat clearer, or something, which is why i used it. but you have made valid points :) - thanks for looking at it!
Re: Palleter
Posted: Sun Nov 03, 2013 2:15 pm
by dkeg
rho, I took your original, and since I'm placing in .Xresources. Obviously have not taken into account xaos' suggestions yet
Code: Select all
PALETTE=$(convert "$1" -colors 16 -format "%c" histogram:info:)
HEXLIST=$(echo "$PALETTE" | sed 's/^.*\#\(.*\) srgb.*/\1/g')
COL=("0" "8" "1" "9" "2" "A" "3" "B" "4" "C" "5" "D" "6" "E" "7" "F");
CLEAN=$(echo $COL | sed 's/^0*//')
x=0
while read line; do
echo -en *color$x: '#'"${CLEAN}$line\n";
let x=x+1
done <<< "$HEXLIST"
clear
output is
Code: Select all
*color0: #2E1A1F
*color1: #4E311F
*color2: #4F342C
*color3: #573843
*color4: #644B31
*color5: #6E5234
*color6: #765B45
*color7: #827F68
*color8: #8A693A
*color9: #91754D
*color10: #9C6B4A
*color11: #9C8258
*color12: #AA8C5D
*color13: #AB6544
*color14: #C8AA76
*color15: #D6BC8A