Last active
August 29, 2015 14:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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