<commit_before>#!/usr/bin/env bash

######################################
# INITIALIZE VARS

CONVERT_CMD=`which convert`
SRC_IMAGE=$1
PWD=`<PASSWORD>`
TRANSPARENT_COLOUR="#FFFFFF"
IMAGE_NAME="favicon"
WEBSITE_DOMAIN="http://www.yourwebsite.com"

######################################
# COLOURS

GREY="\033[90m"
GREEN="\033[32m"
BLUE="\033[34m"
CYAN="\033[36m"
RED="\033[31m"
NO_COLOUR="\033[0m"

COLOUR_COMMENT=$GREY
COLOUR_TAG=$BLUE
COLOUR_ATTR_NAME=$CYAN
COLOUR_ATTR_VALUE=$RED
COLOUR_INTRO=$GREEN

######################################
# REQUIREMENTS

if [ -z $CONVERT_CMD ] || [ ! -f $CONVERT_CMD ] || [ ! -x $CONVERT_CMD ];
then
    echo "ImageMagick needs to be installed to run this script"
    exit;
fi

if [ -z $SRC_IMAGE ];
then
    echo "You must supply a source image as the argument to this command."
    exit;
fi

if [ ! -f $SRC_IMAGE ];
then
    echo "Source image \"$SRC_IMAGE\" does not exist."
    exit;
fi

function generate_png {
    local SIZE=$1
    local SOURCE=$2

    if [ -z "$SOURCE" ];
    then
        SOURCE="$PWD/$IMAGE_NAME-256.png"
    fi

    if [ ! -f $SOURCE ];
    then
        echo "Could not find the source image $SOURCE"
        exit 1;
    fi

    if [[ $SIZE =~ ^([0-9]+)x([0-9]+)$ ]];
    then
        WIDTH=${BASH_REMATCH[1]}
        HEIGHT=${BASH_REMATCH[2]}
    else
        WIDTH=$SIZE
        HEIGHT=$SIZE
    fi

    echo "$IMAGE_NAME-${SIZE}.png"
    $CONVERT_CMD $SOURCE -resize ${WIDTH}x${HEIGHT}! -crop ${WIDTH}x${HEIGHT}+0+0 -alpha On $PWD/$IMAGE_NAME-${SIZE}.png
}

echo "Generating square base image"
# Converts the source image to 256 square, ignoring aspect ratio
generate_png 256 $SRC_IMAGE

######################################
# GENERATE THE VARIOUS SIZE VERSIONS

echo "Generating required versions at different sizes"
generate_png 16
generate_png 32
generate_png 48
generate_png 57
generate_png 64
generate_png 70
generate_png 72
generate_png 114
generate_png 120
generate_png 144
generate_png 150
generate_png 152
# TODO Figure out crop/resize priority etc.
# generate_png 310x150
generate_png 310

######################################
# GENERATE THE FAVICON.ICO FILE

echo "Generating ico"
$CONVERT_CMD \
$PWD/$IMAGE_NAME-16.png \
$PWD/$IMAGE_NAME-32.png \
$PWD/$IMAGE_NAME-48.png \
$PWD/$IMAGE_NAME-64.png \
-colors 256 -background $TRANSPARENT_COLOUR $PWD/$IMAGE_NAME.ico

######################################
# OUTPUT USEFUL MARKUP

echo
echo
echo -e "${COLOUR_COMMENT}_______________________________________________________________________________________${NO_COLOUR}"<commit_msg>Fix alpha weirdness in ico file when not 256 colours<commit_after>#!/usr/bin/env bash

######################################
# INITIALIZE VARS

CONVERT_CMD=`which convert`
SRC_IMAGE=$1
PWD=`pwd`
TRANSPARENT_COLOUR="#FFFFFF"
IMAGE_NAME="favicon"
WEBSITE_DOMAIN="http://www.yourwebsite.com"

######################################
# COLOURS

GREY="\033[90m"
GREEN="\033[32m"
BLUE="\033[34m"
CYAN="\033[36m"
RED="\033[31m"
NO_COLOUR="\033[0m"

COLOUR_COMMENT=$GREY
COLOUR_TAG=$BLUE
COLOUR_ATTR_NAME=$CYAN
COLOUR_ATTR_VALUE=$RED
COLOUR_INTRO=$GREEN

######################################
# REQUIREMENTS

if [ -z $CONVERT_CMD ] || [ ! -f $CONVERT_CMD ] || [ ! -x $CONVERT_CMD ];
then
    echo "ImageMagick needs to be installed to run this script"
    exit;
fi

if [ -z $SRC_IMAGE ];
then
    echo "You must supply a source image as the argument to this command."
    exit;
fi

if [ ! -f $SRC_IMAGE ];
then
    echo "Source image \"$SRC_IMAGE\" does not exist."
    exit;
fi

function generate_png {
    local SIZE=$1
    local SOURCE=$2

    if [ -z "$SOURCE" ];
    then
        SOURCE="$PWD/$IMAGE_NAME-256.png"
    fi

    if [ ! -f $SOURCE ];
    then
        echo "Could not find the source image $SOURCE"
        exit 1;
    fi

    if [[ $SIZE =~ ^([0-9]+)x([0-9]+)$ ]];
    then
        WIDTH=${BASH_REMATCH[1]}
        HEIGHT=${BASH_REMATCH[2]}
    else
        WIDTH=$SIZE
        HEIGHT=$SIZE
    fi

    echo "$IMAGE_NAME-${SIZE}.png"
    $CONVERT_CMD $SOURCE -resize ${WIDTH}x${HEIGHT}! -crop ${WIDTH}x${HEIGHT}+0+0 -alpha On $PWD/$IMAGE_NAME-${SIZE}.png
}

echo "Generating square base image"
# Converts the source image to 256 square, ignoring aspect ratio
generate_png 256 $SRC_IMAGE

######################################
# GENERATE THE VARIOUS SIZE VERSIONS

echo "Generating required versions at different sizes"
generate_png 16
generate_png 32
generate_png 48
generate_png 57
generate_png 64
generate_png 70
generate_png 72
generate_png 114
generate_png 120
generate_png 144
generate_png 150
generate_png 152
# TODO Figure out crop/resize priority etc.
# generate_png 310x150
generate_png 310

######################################
# GENERATE THE FAVICON.ICO FILE

echo "Generating ico"
$CONVERT_CMD \
$PWD/$IMAGE_NAME-16.png \
$PWD/$IMAGE_NAME-32.png \
$PWD/$IMAGE_NAME-48.png \
$PWD/$IMAGE_NAME-64.png \
-background $TRANSPARENT_COLOUR $PWD/$IMAGE_NAME.ico

######################################
# OUTPUT USEFUL MARKUP

echo
echo
echo -e "${COLOUR_COMMENT}_______________________________________________________________________________________${NO_COLOUR}"
{'fraction_non_alphanumeric': 0.19949396652393928, 'fraction_numerical': 0.03853639548462437, 'mean_word_length': 4.358706986444212, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4346102', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1697, 'n_words': 432}