diff --git a/stpkg b/stpkg index b038ff5f548561f387113182a21d28cc3b8db708..2d5ad38c8e3e77f0625e58e2b8b0f40830b655cf 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