Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reduces the colour count of an image and then overlays those colours as cubes onto the image
#!/bin/bash
#Reduces the colour count of an image and then overlays those colours as cubes onto the image
#Developed for Post-Modern Plant Life: An [RHP] CDRs Artist Laboratory https://www.facebook.com/events/1452413868331145/
for file in *.JPG
do
colors=$1
#line number in colours.txt
lineno=1
rm colors.txt
ypos=20
#get path of file
path=$( readlink -f "$( dirname "$file" )" )
#get filename minus extension
file=$(basename "$file")
filename="${file%.*}"
#get extension
extension="${file##*.}"
#convert image to a smallerr scale
convert "$file" -scale 500x "$path"/"$filename"_small."$extension"
#get histogram featuring n colours and save it to colours.txt
convert "$path"/"$filename"_small."$extension" -colors "$colors" -depth 8 -format "%c" histogram:info: | head -n 18 | cut -d# -f2 | cut -ds -f-1 > colors.txt
while [ $lineno -le $colors ]
do
convert "$path"/"$filename"_small."$extension" -fill "#""$(sed -n "$lineno{p}" colors.txt);" -stroke "#FFFFFF" -draw "rectangle 20,$ypos 40,$(($ypos + 20))" "$path"/"$filename"_small."$extension"
lineno=$(($lineno + 1))
ypos=$(($ypos + 20))
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.