<commit_before>###############################################################
# Image Functions
###############################################################

###############################################################
#
# __vector_render <RES> <FILE.svg>
#
# Render Vector Image
# Renders the specified .svg to a .png of the same name
#
###############################################################

__vector_render () {
if [ -z "${__quick}" ]; then
    export __quick='1'
    __force_warn "__quick has not been set correctly. Defaulting to rsvg-convert"
fi

if ! [ "$(__oext "${2}")" = 'svg' ]; then
    __error "File \"${2}\" is not an svg file"
fi

__dpi="$(echo "(96*${1})/128" | bc -l | sed 's/0*$//')"
if [ "${__quick}" = '1' ]; then
# GOD awful hack to catch svg size, since rsvg-convert seems
# buggy
# TODO
# FIX THIS vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
rsvg-convert \
--width="$(echo "($(grep "^   width=\"*\"" < "${2}" | sed -e 's/.*="//' -e 's/"$//')*${1})/128" | bc)" \
-a \
"${2}" \
-o "$(__mext "${2}").png" 1> /dev/null
convert "$(__mext "${2}")"".png" -define png:color-type=6 "$(__mext "$2")"'_'".png"
mv "$(__mext "${2}")"'_'".png" "$(__mext "${2}")"".png"

elif [ "${__quick}" = '0' ]; then
inkscape \
--export-dpi="${__dpi}" \
--export-png "$(__mext "${2}").png" "${2}" 1> /dev/null
convert "$(__mext "${2}")"".png" -define png:color-type=6 "$(__mext "${2}")"'_'".png"
mv "$(__mext "${2}")"'_'".png" "$(__mext "${2}")"".png"
fi
}

###############################################################
#
# __gimp_export <FILE.xcf>
#
# GIMP Export
# Exports a given GIMP file to a PNG file of the same name
#
# Shamelessly stolen from:
# http://stackoverflow.com/a/5846727/7578643
#
###############################################################

__gimp_export () {

if ! [ "$(__oext "${1}")" = 'xcf' ]; then
    __error "File \"${1}\" is not a xcf file"
fi

__gimp_sub () {
gimp -i --batch-interpreter=python-fu-eval -b - << EOF
import gimpfu

def convert(filename):
    img = pdb.gimp_file_load(filename, filename)
    new_name = filename.rsplit(".",1)[0] + ".png"
    layer = pdb.gimp_image_merge_visible_layers(img, 1)

    pdb.gimp_file_save(img, layer, new_name, new_name)
    pdb.gimp_image_delete(img)

convert('${1}')

pdb.gimp_quit(1)
EOF
}

# My instance of GIMP throws some errors no matter what, so
__gimp_sub "${1}" &> /dev/null

}

###############################################################
#
# __optimize <IMAGE.png>
#
# Optimize Image
# Accepts a PNG file as an input, optimizes with optipng, and
# replaces if smaller. Will ignore if given file is not a
# '.png' file.
#
###############################################################

__optimize () {
if [ "$(__oext "${1}")" = 'png' ]; then
    optipng -silent "${1}"<commit_msg>Make optimization not do color type reduction, as Minecraft is borked. Also strip any metadata, since it's not needed, and saves some space.<commit_after>###############################################################
# Image Functions
###############################################################

###############################################################
#
# __vector_render <RES> <FILE.svg>
#
# Render Vector Image
# Renders the specified .svg to a .png of the same name
#
###############################################################

__vector_render () {
if [ -z "${__quick}" ]; then
    export __quick='1'
    __force_warn "__quick has not been set correctly. Defaulting to rsvg-convert"
fi

if ! [ "$(__oext "${2}")" = 'svg' ]; then
    __error "File \"${2}\" is not an svg file"
fi

__dpi="$(echo "(96*${1})/128" | bc -l | sed 's/0*$//')"
if [ "${__quick}" = '1' ]; then
# GOD awful hack to catch svg size, since rsvg-convert seems
# buggy
# TODO
# FIX THIS vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
rsvg-convert \
--width="$(echo "($(grep "^   width=\"*\"" < "${2}" | sed -e 's/.*="//' -e 's/"$//')*${1})/128" | bc)" \
-a \
"${2}" \
-o "$(__mext "${2}").png" 1> /dev/null
convert "$(__mext "${2}")"".png" -define png:color-type=6 "$(__mext "$2")"'_'".png"
mv "$(__mext "${2}")"'_'".png" "$(__mext "${2}")"".png"

elif [ "${__quick}" = '0' ]; then
inkscape \
--export-dpi="${__dpi}" \
--export-png "$(__mext "${2}").png" "${2}" 1> /dev/null
convert "$(__mext "${2}")"".png" -define png:color-type=6 "$(__mext "${2}")"'_'".png"
mv "$(__mext "${2}")"'_'".png" "$(__mext "${2}")"".png"
fi
}

###############################################################
#
# __gimp_export <FILE.xcf>
#
# GIMP Export
# Exports a given GIMP file to a PNG file of the same name
#
# Shamelessly stolen from:
# http://stackoverflow.com/a/5846727/7578643
#
###############################################################

__gimp_export () {

if ! [ "$(__oext "${1}")" = 'xcf' ]; then
    __error "File \"${1}\" is not a xcf file"
fi

__gimp_sub () {
gimp -i --batch-interpreter=python-fu-eval -b - << EOF
import gimpfu

def convert(filename):
    img = pdb.gimp_file_load(filename, filename)
    new_name = filename.rsplit(".",1)[0] + ".png"
    layer = pdb.gimp_image_merge_visible_layers(img, 1)

    pdb.gimp_file_save(img, layer, new_name, new_name)
    pdb.gimp_image_delete(img)

convert('${1}')

pdb.gimp_quit(1)
EOF
}

# My instance of GIMP throws some errors no matter what, so
__gimp_sub "${1}" &> /dev/null

}

###############################################################
#
# __optimize <IMAGE.png>
#
# Optimize Image
# Accepts a PNG file as an input, optimizes with optipng, and
# replaces if smaller. Will ignore if given file is not a
# '.png' file.
#
###############################################################

__optimize () {
if [ "$(__oext "${1}")" = 'png' ]; then
    optipng -nc -strip all -silent "${1}"
{'fraction_non_alphanumeric': 0.3590014064697609, 'fraction_numerical': 0.020042194092827006, 'mean_word_length': 4.723340040241449, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '4779502', 'n_tokens_mistral': 2035, 'n_tokens_neox': 1983, 'n_words': 516}