From 5f0baad441bf5bebb74c578a2bbbbd7dcd8757ab Mon Sep 17 00:00:00 2001 From: salixor <salixor@pm.me> Date: Sat, 26 Oct 2024 00:10:18 +0200 Subject: [PATCH] Fix missing quotes in sticker processing + use elif --- stpkg | 83 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/stpkg b/stpkg index b038ff5..2d5ad38 100755 --- a/stpkg +++ b/stpkg @@ -624,62 +624,57 @@ process_sticker_file() { # Don't convert image, upload it as it is # local DEST_TYPE=$INIT_TYPE - cp ${FILE} ${TEMP} - - else - if [[ ${animatedFiletype[$INIT_TYPE]} ]]; then - # - # Convert animated image - # - if [[ "$INIT_TYPE" == "image/apng" ]] && [[ "$STPKG_ALLOW_APNG" == "yes" ]]; then - # FIXME: properly crop apngs - - local DEST_TYPE="image/apng" - - # 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 ":" "-1") - - ffmpeg -y -loglevel warning -f apng -i "${FILE}" -plays 0 -vf scale=${DEST_DIMENSIONS} -f apng "${TEMP}" >/dev/null - else - local DEST_TYPE=$STPKG_ANIMATED_TARGET_FILETYPE - local DEST_EXT=$(file_get_ext_from_type "$DEST_TYPE") - - local backgroundColor="`convert "${FILE}[0]" -format "%[pixel:u.p{0,0}]" info:`" - convert "${INIT_EXT}:${FILE}" -dispose previous -background "${backgroundColor}" -trim -layers TrimBounds -coalesce "$DEST_EXT:${TEMP}" 1>&2 \ - || die "$NAME failed trimming the sticker" - - # 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 "x" "") + cp "$FILE" "$TEMP" + elif [[ ${animatedFiletype[$INIT_TYPE]} ]]; then + # + # Convert animated image + # + if [[ "$INIT_TYPE" == "image/apng" ]] && [[ "$STPKG_ALLOW_APNG" == "yes" ]]; then + # FIXME: properly crop apngs - convert "${TEMP}" -coalesce -dispose previous -resize ${DEST_DIMENSIONS} "$DEST_EXT:${TEMP}" 1>&2 \ - || die "$NAME failed resizing the sticker" + local DEST_TYPE="image/apng" - # Can't optimize the gif because discord doesn't know how to display them properly (for bridged channels) - #convert "${TEMP}" -coalesce -layers Optimize "$DEST_EXT:${TEMP}" 1>&2 \ - fi + # 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 ":" "-1") + ffmpeg -y -loglevel warning -f apng -i "${FILE}" -plays 0 -vf scale=${DEST_DIMENSIONS} -f apng "${TEMP}" >/dev/null else - # - # Convert fixed image - # - local DEST_TYPE=$STPKG_IMAGE_TARGET_FILETYPE + local DEST_TYPE=$STPKG_ANIMATED_TARGET_FILETYPE local DEST_EXT=$(file_get_ext_from_type "$DEST_TYPE") - convert "$FILE" -trim "${INIT_EXT}:${TEMP}" + local backgroundColor="`convert "${FILE}[0]" -format "%[pixel:u.p{0,0}]" info:`" + convert "${INIT_EXT}:${FILE}" -dispose previous -background "${backgroundColor}" -trim -layers TrimBounds -coalesce "$DEST_EXT:${TEMP}" 1>&2 \ + || die "$NAME failed trimming the sticker" # Get sizes - local INIT_WIDTH=$(file_get_width "$TEMP") - local INIT_HEIGHT=$(file_get_height "$TEMP") + 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 "x" "") - convert "$TEMP" -bordercolor none -border 1 -background none -gravity center -trim +repage -resize ${DEST_DIMENSIONS} "${DEST_EXT}:${TEMP}" 1>&2 \ - || die "$NAME failed converting the sticker" + convert "${TEMP}" -coalesce -dispose previous -resize ${DEST_DIMENSIONS} "$DEST_EXT:${TEMP}" 1>&2 \ + || die "$NAME failed resizing the sticker" + + # Can't optimize the gif because discord doesn't know how to display them properly (for bridged channels) + #convert "${TEMP}" -coalesce -layers Optimize "$DEST_EXT:${TEMP}" 1>&2 \ fi + else + # + # Convert fixed image + # + local DEST_TYPE=$STPKG_IMAGE_TARGET_FILETYPE + local DEST_EXT=$(file_get_ext_from_type "$DEST_TYPE") + + convert "$FILE" -trim "${INIT_EXT}:${TEMP}" + + # 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 "x" "") + convert "$TEMP" -bordercolor none -border 1 -background none -gravity center -trim +repage -resize ${DEST_DIMENSIONS} "${DEST_EXT}:${TEMP}" 1>&2 \ + || die "$NAME failed converting the sticker" fi # Get real final dimensions for json -- GitLab