Last active
April 7, 2017 08:04
-
-
Save kaplas/56d2b7146e514bbe9d7120ab2bd2008c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
set -e | |
if [[ "$1" != /* ]]; then | |
# Relative path name | |
FILENAME_WITH_EXT=$(basename "$1") | |
FILENAME="${FILENAME_WITH_EXT%.*}" | |
ABSPATH=$(unset CDPATH && cd "$(dirname "$0")" && echo $PWD) | |
DIRNAME="$ABSPATH/$FILENAME" | |
FILEEXT="${FILENAME_WITH_EXT##*.}" | |
ORIG_FILEPATH="$ABSPATH/$FILENAME_WITH_EXT" | |
else | |
# Absolute path name | |
FILENAME_WITH_EXT=$(basename "$1") | |
DIRNAME="${1%.*}" | |
FILENAME="${FILENAME_WITH_EXT%.*}" | |
FILEEXT="${FILENAME_WITH_EXT##*.}" | |
ORIG_FILEPATH="$1" | |
fi | |
# Create a new directory, new to the original file, for storing new color variants | |
echo "Creating the output directory" | |
mkdir -p "$DIRNAME" | |
NEW_FILEPATH="" | |
set_new_filepath(){ | |
local MODIFIER="$1" | |
NEW_FILEPATH="$DIRNAME/$FILENAME-$MODIFIER.$FILEEXT" | |
} | |
echo "Creating a gray scale version of image" | |
set_new_filepath "gray" | |
GRAY_FILEPATH="$NEW_FILEPATH" | |
# If you want use the image in slides (ie. crop image to 16:9 and make it smaller) : | |
convert "$ORIG_FILEPATH" -colorspace gray -geometry 1920x1080^ -gravity center -crop 1920x1080+0+0 "$GRAY_FILEPATH" | |
# If you just want to create colourful version of the original pic (without cropping and etc.) : | |
# convert "$ORIG_FILEPATH" -colorspace gray "$GRAY_FILEPATH" | |
COLORS=( | |
"rgb(2, 33, 90)" "rgb(230, 245, 221)" | |
"rgb(70, 45, 152)" "rgb(255, 240, 212)" | |
"rgb(79, 16, 89)" "rgb(238, 243, 245)" | |
"rgb(3, 52, 64)" "rgb(206, 236, 228)" | |
"rgb(8, 90, 75)" "rgb(225, 220, 220)" | |
"rgb(56, 157, 70)" "rgb(255, 244, 179)" | |
"rgb(253, 145, 146)" "rgb(242, 238, 230)" | |
"rgb(129, 157, 174)" "rgb(255, 244, 179)" | |
"rgb(252, 84, 71)" "rgb(238, 243, 245)" | |
"rgb(190, 196, 229)" "rgb(238, 243, 245)" | |
"rgb(239, 214, 196)" "rgb(255, 255, 255)" | |
"rgb(225, 220, 220)" "rgb(255, 255, 255)" | |
) | |
printf "%s" "Creating color washed versions of image" | |
for ((c=0;c<${#COLORS[@]};c=c+2)); do | |
printf "%s" "." | |
NUMBER=$(($((c/2))+1)) | |
DARK_COLOR=${COLORS[c]} | |
LIGHT_COLOR=${COLORS[c+1]} | |
set_new_filepath "gradient" | |
GRADIENT_FILEPATH="$NEW_FILEPATH" | |
convert \( -size 1x1 xc:"$DARK_COLOR" xc:"$LIGHT_COLOR" +append \) -filter cubic -resize 256x1! -scale 256x20! "$GRADIENT_FILEPATH" | |
set_new_filepath "$NUMBER" | |
convert "$GRAY_FILEPATH" "$GRADIENT_FILEPATH" -clut "$NEW_FILEPATH" | |
done | |
printf "%s\n" " " | |
# Remove the gradient file, because we don't need that one | |
echo "Removing temporary files" | |
rm -f "$GRADIENT_FILEPATH" | |
echo "All color versions created" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment