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:

Re: Palleter

Unread post by rhowaldt » Sun Nov 03, 2013 2:22 pm

^ very nice!
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
xaos52
The Good Doctor
Posts: 190
Joined: Thu Aug 15, 2013 11:59 am
Location: Eernegem, Belgium

Re: Palleter

Unread post by xaos52 » Mon Nov 04, 2013 2:44 pm

Bug squashing - make the script fool-proof.
New version based on the original sript:

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

# Squashed Bugs

#   Bug #1:
#     when the script is launched without arguments, it hangs in convert
#     because convert is then expecting its input from stdin.
#     This is not bad in itself, but it can be confusing because the user
#     is not aware of it.
#   Solution for Bug #1:
#     Test for $1 not equal to the empty string to read from an image file.
#     If there is no argument to the program, warn the user about the program
#     reading its input from stdin.

#   Bug #2:
#     The convert command produces an empty line as the last line in its output.
#     There is no need to transform that empty line to an escape sequence,
#     though there don't seem to be any averse effects.
#   Solution for Bug #2:
#     Test for for an empty line within the read command and break when you encounter it.

[[ "$1" ]] || {
    printf '%s\n' "You have not supplied the path to an image to be sampled.
${0} will read the image from stdin.

If that is what you intended, you can ignore this message.

If that is _NOT_ what you intended, press Ctrl-D on an empty line to stop reading stdin.
There will be an  error message from the 'convert' utility that you can ignore.

Restart the program with the path to the image as argument."
} >&2

COL=("0" "8" "1" "9" "2" "A" "3" "B" "4" "C" "5" "D" "6" "E" "7" "F");
x=0

while read -r line; do
    [[ "$line" ]] || continue
    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 » Mon Nov 04, 2013 2:56 pm

thanks for the squash and the link before, of course it makes more sense in the evening than in the morning :D
..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 » Mon Nov 04, 2013 3:01 pm

Doesi t not depend on how late in the evening it is?
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 » Mon Nov 04, 2013 3:44 pm

ah xaos, good points. i usually fix for at least the $1-check but i was so excited at having made another script after some time that i slapped it online immediately :) - thanks, very nice.
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
xaos52
The Good Doctor
Posts: 190
Joined: Thu Aug 15, 2013 11:59 am
Location: Eernegem, Belgium

Re: Palleter

Unread post by xaos52 » Mon Nov 04, 2013 5:34 pm

No problem, Rhowald.
I am glad you can handle criticism positively.
What you are saying is true for almost all new scripts.
All need some usage, throwing out all sorts of arguments at them, to weed out the weaknesses and make em better.
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 » Mon Nov 04, 2013 11:27 pm

much agreed xaos. and i really appreciate people (such as yourself) taking the time to look at these scripts and improving on them. in the end, all we really want is to make nice shit, right? so let's do it together while we're at this BBQ, combined efforts and all :)
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
mrneilypops
Bad Advice Dog
Posts: 143
Joined: Wed Oct 17, 2012 9:15 pm
Location: Luxembourg
Contact:

Re: Palleter

Unread post by mrneilypops » Fri Nov 08, 2013 7:40 pm

@xaos52
I am using your version of palleter but this is the output it gives me in terminator and urxvt;

Code: Select all

live@wheezy:~$ ./palleter1.sh /home/live/images/lightrails.png
]P0080604]P8241F20]P1261A12]P92D231C]P2352B25]PA48392E]P3532510]PB5C4738]P46E5849]PC90705A]P59B532A]PDAC8C72]P6CEB197]PED39E6F]P7D9BFA7]PFF9F2E9live@wheezy:~$ 
Probably me having a really blonde day but how can I get a more sensible output?
The colours work but it is a bit of a pain copy/pasting into ~/.Xresources.

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 » Fri Nov 08, 2013 7:46 pm

The script is not ready yet.
For the moment it works only for the console and for xterm.

I am working on relieving you from that pain, but you will have to be a little patient.

I expect the script to be fully functional in the course of next week.
Connected. Take this REPL, brother, and may it serve you well.

User avatar
mrneilypops
Bad Advice Dog
Posts: 143
Joined: Wed Oct 17, 2012 9:15 pm
Location: Luxembourg
Contact:

Re: Palleter

Unread post by mrneilypops » Fri Nov 08, 2013 7:54 pm

@xaos52
Perfect...just testing at the moment and I don't want to appear too lazy with copy/paste.
The colours come out great (for me) on my test;

http://fav.me/d6tgysu

...but it would be great to just have the column of colours to copy into ~/.Xresources...maybe...

keep up the FAB work...this is goin down a storm on the grapevine!

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

Re: Palleter

Unread post by dkeg » Fri Nov 08, 2013 8:07 pm

I posted a solution that works for me a bit further up in the thread. I have made adjustments based on updates from others (the doctor). I named my paletterX for differentation.

Code: Select all

#!/bin/bash
# takes an image and creates a color palette from it
# 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");
CLEAN=$(echo $COL | sed 's/^0*//')

x=0

## Get the ouput of the color palette
while read -r line; do
    [[ "$line" ]] || continue
    echo -en *color$x: '#'"${CLEAN}$line\n";
    x=$((x+1))
done < <(convert "$1" -colors 16 -format "%c" histogram:info: | sed 's/^.*\#\(.*\) srgb.*/\1/g')
I use this way

Code: Select all

./paletterX ~/path/to/wall.jpg > temp && [editor] temp &
then I can simply c/p the output accordingly.

also you could have a look at this and this script might prove useful too.

edit - I see xaos already responded, but I already typed all this up, so I'm leaving it :D

Work hard; Complain less

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 » Fri Nov 08, 2013 8:13 pm

haha OK :)
Just hold your horses for a while yet.
It is going to happen.
Connected. Take this REPL, brother, and may it serve you well.

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

Re: Palleter

Unread post by dkeg » Fri Nov 08, 2013 8:16 pm

I'll tell ya, this whole thing has really turned into quite an awesome and awe inspiring project. seriously, this final result is going to be great. We Rock!!

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 » Fri Nov 08, 2013 8:30 pm

thanks again for all the work expanding on this script xaos and dkeg. indeed, it's gonna be beautiful, and we'll never be at a loss for colorthemes anymore :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
mrneilypops
Bad Advice Dog
Posts: 143
Joined: Wed Oct 17, 2012 9:15 pm
Location: Luxembourg
Contact:

Re: Palleter

Unread post by mrneilypops » Fri Nov 08, 2013 10:17 pm

Thanks All - I really appreciate this work!

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 09, 2013 12:36 pm

@rhowald - this would not have happened without your brilliant convert/histogram idea.
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 » Sat Nov 09, 2013 1:05 pm

@xaos: thanks mate. keep up the good shit :)
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
xaos52
The Good Doctor
Posts: 190
Joined: Thu Aug 15, 2013 11:59 am
Location: Eernegem, Belgium

Re: Palleter

Unread post by xaos52 » Mon Nov 18, 2013 11:35 am

Has anyone tried the version of palleter as posted earlier by 'fog' on terminator?

I could have sworn that it worked for me earlier, but it does no more.
Not on a jessie based system, nor on a sid based one.
I have no clue why the behaviour changed.

Can someone else, who is used to using terminator, test that script again and let me know if it works for him/her.

I am struggling to find a method to change terminal colors in terminator dynamically.

Thanks to the able and the willing,
xaos

PS: I am now thinking I was wrong, and it did not work to dynamically change the colors.
I guess fog just used the output from the script and copied it into the terminator config file.
It never worked 'on the fly'.

I could update the config file automatically with the new palette, saving some 'manual editing'.
Suspending for now.
Connected. Take this REPL, brother, and may it serve you well.

User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: Palleter

Unread post by bones » Mon Apr 28, 2014 9:52 pm

I'm just trying to make sure I understand how the paletter/paletterx script works. When you invoke the script, what is happening? Where does the info that it pulls from the current wallpaper go? When I invoke the script, I seem to only get a blinking cursor, and it never returns to a new bash prompt. What further steps do I need to take?

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

Re: Palleter

Unread post by dkeg » Mon Apr 28, 2014 10:07 pm

Code: Select all

./palleterX /path/to/image

Work hard; Complain less

Post Reply