Palleter

Submitted scripts and programs
Forum rules
Your own work only.
User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Palleter

Unread post by rhowaldt » Wed Oct 30, 2013 10:42 pm

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
tigermonk
here's the resulting scheme:
nice 'n pink
nice 'n pink
tigermonk.png (10.83 KiB) Viewed 8605 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 :)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
wuxmedia
Grasshopper
Posts: 6447
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Palleter

Unread post by wuxmedia » Wed Oct 30, 2013 11:33 pm

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.
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
ivanovnegro
Minister of Truth
Posts: 5449
Joined: Wed Oct 17, 2012 11:12 pm

Re: Palleter

Unread post by ivanovnegro » Thu Oct 31, 2013 1:08 am

Awesome Rho. I like it and will take it to my collection without hesitating.

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Palleter

Unread post by DebianJoe » Thu Oct 31, 2013 2:57 am

*applause*
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Palleter

Unread post by machinebacon » Thu Oct 31, 2013 4:48 am

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
..gnutella..

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Palleter

Unread post by GekkoP » Thu Oct 31, 2013 9:51 am

wow! Really great effort here. Will use it next time I want to pimp my bbq.

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Palleter

Unread post by rhowaldt » Thu Oct 31, 2013 10:02 am

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
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Palleter

Unread post by DebianJoe » Thu Oct 31, 2013 10:11 am

@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.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: Palleter

Unread post by dkeg » Thu Oct 31, 2013 1:32 pm

thanks for working up and sharing rho! and a great name too!

Work hard; Complain less

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Palleter

Unread post by rhowaldt » Thu Oct 31, 2013 4:19 pm

@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 :)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
fog
Mr. Saggy Tits
Posts: 28
Joined: Mon Jan 14, 2013 12:13 pm
Location: /home/fog
Contact:

Re: Palleter

Unread post by fog » Sat Nov 02, 2013 8:39 am

THANK YOU.
This is awesome. My -new- favorite, must-have script, in every installation.

Image

Thanks again MR R :)
I’m not antisocial, I’m just not user friendly.
photos || blog || dArt

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Palleter

Unread post by rhowaldt » Sat Nov 02, 2013 10:36 am

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 :)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
fog
Mr. Saggy Tits
Posts: 28
Joined: Mon Jan 14, 2013 12:13 pm
Location: /home/fog
Contact:

Re: Palleter

Unread post by fog » Sat Nov 02, 2013 12:59 pm

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 :)
I’m not antisocial, I’m just not user friendly.
photos || blog || dArt

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Palleter

Unread post by rhowaldt » Sat Nov 02, 2013 5:22 pm

^ 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
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
fog
Mr. Saggy Tits
Posts: 28
Joined: Mon Jan 14, 2013 12:13 pm
Location: /home/fog
Contact:

Re: Palleter

Unread post by fog » Sat Nov 02, 2013 6:34 pm

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
I’m not antisocial, I’m just not user friendly.
photos || blog || dArt

User avatar
xaos52
The Good Doctor
Posts: 190
Joined: Thu Aug 15, 2013 11:59 am
Location: Eernegem, Belgium

Re: Palleter

Unread post by xaos52 » Sat Nov 02, 2013 7:01 pm

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')

Connected. Take this REPL, brother, and may it serve you well.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Palleter

Unread post by machinebacon » Sun Nov 03, 2013 2:33 am

Is the space intentional in the last line between the two < ?
..gnutella..

User avatar
xaos52
The Good Doctor
Posts: 190
Joined: Thu Aug 15, 2013 11:59 am
Location: Eernegem, Belgium

Re: Palleter

Unread post by xaos52 » Sun Nov 03, 2013 10:36 am

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.
Connected. Take this REPL, brother, and may it serve you well.

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Palleter

Unread post by rhowaldt » Sun Nov 03, 2013 1:12 pm

@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!
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: Palleter

Unread post by dkeg » Sun Nov 03, 2013 2:15 pm

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

Work hard; Complain less

Post Reply