~scripts
40 itemsDownload ./*


..
dzen2
tiling
vosh
4cdl
4trips
alarm
ambient
battery-monitor
checkit
cleverbot.py
clock
color-gen
colors-hex
compton
dailywall
dmenu
importw
indexer
keep-on
mp3ogg
orage
pipes
pipes.x
rain
randwall
screen-dim
screencast
screencast2
scrot
scrotw
search
skull
slocker
starwars
streamit
sumnum
tty-colorize
usrmount
ytp
ytplay


scriptscolor-gen
2 years agoDownloadRawClose


#!/bin/bash
#
# Description: Generate hex colors from a picture
# Usage:       sh ./color-gen image.jpg 16
#

N=${2:-8}
COL=$(convert "$1" -define histogram:unique-colors=true -colors $N \
    -format %c histogram:info:- | sed 's/.*#/#/;' | cut -c -7 | sort -nr)

OUT=""
while IFS=" " read -ra ARR; do
    for X in "${ARR[@]}"; do
        OUT="$OUT<span style=\"background: $X;\" onclick=\"setbg(this);\">$X</span>"
    done
done <<< "$COL"

TMP="/tmp/color-generate.html"
echo -e "<!DOCTYPE html>\n" \
        "<html>\n" \
        "<head>\n" \
        "<title>Colors[$N] from \"$1\"</title>\n" \
        "<style type=\"text/css\">\n" \
        "html { height: 100%; }\n" \
        "body {\n" \
        "    margin: 0; padding: 0; min-height: 100%;\n" \
        "    background: #17181A; color: #000;\n" \
        "    transition: background .2s ease;\n" \
        "}\n" \
        "span {\n" \
        "    display: inline-block; width: 128px; height: 64px;\n" \
        "    text-align: center; line-height: 64px;\n" \
        "}\n" \
        "div,img { max-width: calc(128px * 8); }\n" \
        "</style>\n" \
        "<script type=\"text/javascript\">\n" \
        "function setbg(x) { document.body.style.background=x?x.style.background:x; }\n" \
        "</script>\n" \
        "</head>\n" \
        "<body>\n" \
        "<br /><br />\n" \
        "<center>\n" \
        "<div>\n" \
        "$OUT" \
        "</div>\n" \
        "<br /><br />\n" \
        "<img src=\"file://$(pwd)/$1\" onclick=\"setbg('');\" />\n" \
        "</center>\n" \
        "<br /><br />\n" \
        "</body>\n" \
        "</html>\n" > $TMP

$BROWSER "$TMP"

exit 0

Top
twily at openmailbox dot org
©twily.info 2013 - 2017



744 093 visits
... ^ v