Page 2 of 3

Re: Palleter

Posted: Sun Nov 03, 2013 2:22 pm
by rhowaldt
^ very nice!

Re: Palleter

Posted: Mon Nov 04, 2013 2:44 pm
by xaos52
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')



Re: Palleter

Posted: Mon Nov 04, 2013 2:56 pm
by machinebacon
thanks for the squash and the link before, of course it makes more sense in the evening than in the morning :D

Re: Palleter

Posted: Mon Nov 04, 2013 3:01 pm
by xaos52
Doesi t not depend on how late in the evening it is?

Re: Palleter

Posted: Mon Nov 04, 2013 3:44 pm
by rhowaldt
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.

Re: Palleter

Posted: Mon Nov 04, 2013 5:34 pm
by xaos52
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.

Re: Palleter

Posted: Mon Nov 04, 2013 11:27 pm
by rhowaldt
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 :)

Re: Palleter

Posted: Fri Nov 08, 2013 7:40 pm
by mrneilypops
@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.

Re: Palleter

Posted: Fri Nov 08, 2013 7:46 pm
by xaos52
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.

Re: Palleter

Posted: Fri Nov 08, 2013 7:54 pm
by mrneilypops
@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!

Re: Palleter

Posted: Fri Nov 08, 2013 8:07 pm
by dkeg
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

Re: Palleter

Posted: Fri Nov 08, 2013 8:13 pm
by xaos52
haha OK :)
Just hold your horses for a while yet.
It is going to happen.

Re: Palleter

Posted: Fri Nov 08, 2013 8:16 pm
by dkeg
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!!

Re: Palleter

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

Re: Palleter

Posted: Fri Nov 08, 2013 10:17 pm
by mrneilypops
Thanks All - I really appreciate this work!

Re: Palleter

Posted: Sat Nov 09, 2013 12:36 pm
by xaos52
@rhowald - this would not have happened without your brilliant convert/histogram idea.

Re: Palleter

Posted: Sat Nov 09, 2013 1:05 pm
by rhowaldt
@xaos: thanks mate. keep up the good shit :)

Re: Palleter

Posted: Mon Nov 18, 2013 11:35 am
by xaos52
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.

Re: Palleter

Posted: Mon Apr 28, 2014 9:52 pm
by bones
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?

Re: Palleter

Posted: Mon Apr 28, 2014 10:07 pm
by dkeg

Code: Select all

./palleterX /path/to/image