Skip to content

Instantly share code, notes, and snippets.

@hellocatfood
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hellocatfood/dde4d14d08ee697bfaa7 to your computer and use it in GitHub Desktop.
Save hellocatfood/dde4d14d08ee697bfaa7 to your computer and use it in GitHub Desktop.
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