Skip to content
Extraits de code Groupes Projets
Valider e398f91b rédigé par Elliu's avatar Elliu
Parcourir les fichiers

Fix gif generation and image dimensions

Fix gif cropping for weird gifs
Remove gif optimization as discord doesn't know how to display them
Fix output dimensions for pictures with big alpha borders
parent b73ff500
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -550,14 +550,11 @@ __list() { ...@@ -550,14 +550,11 @@ __list() {
done done
} }
# Usage: process_sticker_file <filename> <&JSON> __get_dest_dimensions() {
process_sticker_file() { local INIT_WIDTH=$1
FILE="$1" local INIT_HEIGHT=$2
local -n JSON_REF="$2" local MAX_WIDTH=$3
local MAX_HEIGHT=$3
# Get sizes
local INIT_WIDTH=$(file_get_width "$FILE")
local INIT_HEIGHT=$(file_get_height "$FILE")
local WIDTH_RATIO="$(echo "scale=10; $INIT_WIDTH/$STPKG_MAX_WIDTH" | bc)" local WIDTH_RATIO="$(echo "scale=10; $INIT_WIDTH/$STPKG_MAX_WIDTH" | bc)"
local HEIGHT_RATIO="$(echo "scale=10; $INIT_HEIGHT/$STPKG_MAX_HEIGHT" | bc)" local HEIGHT_RATIO="$(echo "scale=10; $INIT_HEIGHT/$STPKG_MAX_HEIGHT" | bc)"
...@@ -578,6 +575,14 @@ process_sticker_file() { ...@@ -578,6 +575,14 @@ process_sticker_file() {
local DEST_WIDTH=$INIT_WIDTH local DEST_WIDTH=$INIT_WIDTH
fi fi
echo "${DEST_WIDTH}x${DEST_HEIGHT}"
}
# Usage: process_sticker_file <filename> <&JSON>
process_sticker_file() {
FILE="$1"
local -n JSON_REF="$2"
# Get the names and extensions # Get the names and extensions
local INIT_TYPE=$(file_get_type "$FILE") local INIT_TYPE=$(file_get_type "$FILE")
local INIT_EXT=$(file_get_ext_from_type "$INIT_TYPE") local INIT_EXT=$(file_get_ext_from_type "$INIT_TYPE")
...@@ -606,13 +611,20 @@ process_sticker_file() { ...@@ -606,13 +611,20 @@ process_sticker_file() {
local DEST_TYPE=$STPKG_ANIMATED_TARGET_FILETYPE local DEST_TYPE=$STPKG_ANIMATED_TARGET_FILETYPE
local DEST_EXT=$(file_get_ext_from_type "$DEST_TYPE") local DEST_EXT=$(file_get_ext_from_type "$DEST_TYPE")
convert "${FILE}" -coalesce -background none -trim -layers TrimBounds "$DEST_EXT:${TEMP}" 1>&2 \ local backgroundColor="`convert "${FILE}[0]" -format "%[pixel:u.p{0,0}]" info:`"
convert "${FILE}" -dispose previous -background "${backgroundColor}" -trim -layers TrimBounds -coalesce "$DEST_EXT:${TEMP}" 1>&2 \
|| die "$NAME failed trimming the sticker" || die "$NAME failed trimming the sticker"
convert "${TEMP}" -coalesce -dispose Background -resize ${DEST_WIDTH}x${DEST_HEIGHT} "$DEST_EXT:${TEMP}" 1>&2 \
# Get sizes
local INIT_WIDTH=$(file_get_width "${TEMP}")
local INIT_HEIGHT=$(file_get_height "${TEMP}")
local DEST_DIMENSIONS=$(__get_dest_dimensions $INIT_WIDTH $INIT_HEIGHT $STPKG_MAX_WIDTH $STPKG_MAX_HEIGHT)
convert "${TEMP}" -coalesce -dispose previous -resize ${DEST_DIMENSIONS} "$DEST_EXT:${TEMP}" 1>&2 \
|| die "$NAME failed resizing the sticker" || die "$NAME failed resizing the sticker"
#convert "${TEMP}" -coalesce -layers OptimizePlus -layers RemoveDups -layers OptimizeTransparency "$DEST_EXT:${TEMP}" 1>&2 \
convert "${TEMP}" -coalesce -layers Optimize "$DEST_EXT:${TEMP}" 1>&2 \ # Can't optimize the gif because discord doesn't know how to display them properly (for bridged channels)
|| die "$NAME failed optimizing the sticker" #convert "${TEMP}" -coalesce -layers Optimize "$DEST_EXT:${TEMP}" 1>&2 \
else else
# #
...@@ -621,13 +633,18 @@ process_sticker_file() { ...@@ -621,13 +633,18 @@ process_sticker_file() {
local DEST_TYPE=$STPKG_IMAGE_TARGET_FILETYPE local DEST_TYPE=$STPKG_IMAGE_TARGET_FILETYPE
local DEST_EXT=$(file_get_ext_from_type "$DEST_TYPE") local DEST_EXT=$(file_get_ext_from_type "$DEST_TYPE")
convert "$FILE" -bordercolor none -border 1 -background none -gravity center -trim +repage -resize ${DEST_WIDTH}x${DEST_HEIGHT} "${DEST_EXT}:${TEMP}" 1>&2 \ # Get sizes
local INIT_WIDTH=$(file_get_width "$FILE")
local INIT_HEIGHT=$(file_get_height "$FILE")
local DEST_DIMENSIONS=$(__get_dest_dimensions $INIT_WIDTH $INIT_HEIGHT $STPKG_MAX_WIDTH $STPKG_MAX_HEIGHT)
convert "$FILE" -bordercolor none -border 1 -background none -gravity center -trim +repage -resize ${DEST_DIMENSIONS} "${DEST_EXT}:${TEMP}" 1>&2 \
|| die "$NAME failed converting the sticker" || die "$NAME failed converting the sticker"
fi fi
fi fi
# TODO: correctly get max width/height for animated # Get real final dimensions for json
DEST_WIDTH=$(file_get_width "$TEMP") DEST_WIDTH=$(file_get_width "$TEMP")
DEST_HEIGHT=$(file_get_height "$TEMP") DEST_HEIGHT=$(file_get_height "$TEMP")
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter