Skip to content

Instantly share code, notes, and snippets.

@hamid-elaosta
Created December 1, 2018 14:06
Show Gist options
  • Select an option

  • Save hamid-elaosta/6c1b2bae6d01bf6399e6f82282fd12fc to your computer and use it in GitHub Desktop.

Select an option

Save hamid-elaosta/6c1b2bae6d01bf6399e6f82282fd12fc to your computer and use it in GitHub Desktop.
Hue rotation script for batch image conversion (Created for modifying fingerprint scanner animation on OnePlus6T)
#!/usr/bin/env bash
# Batch hue rotation script using ImageMagick's 'convert'
INPUT_DIR=$(pwd)/input
OUTPUT_DIR=$(pwd)/output-$1
if [ -z "$1" ] || [ "$1" -lt 100 ] || [ "$1" -gt 300 ];
then
echo "Specify a hue rotation value between 100 and 300. 100 is 'no rotation' and 300 is 'full rotation'"
echo "Usage: $0 <value>"
echo "Output will be placed in a directory named $OUTPUT_DIR<value>"
exit 1
fi
if [ ! -d "$INPUT_DIR" ];
then
echo "Input directory not found: $INPUT_DIR"
exit 1
fi
if [ -z "$(ls -A "$INPUT_DIR")" ];
then
echo "Input directory is empty: $INPUT_DIR"
exit 1
fi
if [ -d "$OUTPUT_DIR" ] && [ ! -z "$(ls -A "$OUTPUT_DIR")" ];
then
echo "WARNING: Output directory is not empty. Exiting so I don't overwrite your files. Move them and run again."
exit 1
elif [ ! -d "$OUTPUT_DIR" ];
then
mkdir "$OUTPUT_DIR"
fi
INPUT_FILES=()
while IFS= read -r -d $'\0'; do
INPUT_FILES+=("$REPLY")
done < <(find "$INPUT_DIR" -type f -name "*.png" -printf "%f\0")
for i in "${INPUT_FILES[@]}";
do
convert -debug "Resource" "$INPUT_DIR/$i" -set option:modulate:colorspace hsb -modulate 100,100,"$1" "$OUTPUT_DIR/$i"
done
@hamid-elaosta
Copy link
Copy Markdown
Author

hamid-elaosta commented Dec 1, 2018

hue-change
Example. Number at end of file name is rotation value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment