From 219f6556f518991185917b4833858d6fb544693f Mon Sep 17 00:00:00 2001 From: Elliu <elliu@hashi.re> Date: Mon, 15 Aug 2022 15:35:31 +0200 Subject: [PATCH] Fix conversion when not trusted --- stpkg | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/stpkg b/stpkg index 275b14a..6d96025 100755 --- a/stpkg +++ b/stpkg @@ -1,5 +1,10 @@ #!/bin/bash +# TODO: +# Scale up, not only down +# Fail on remove empty sticker pack dir +# Test trusted source + shopt -s nocasematch # Case insensitive STPKG_CONF_FILE=~/.config/stpkg.sh @@ -632,29 +637,40 @@ process_sticker_file() { # Convert animated image # local DEST_TYPE=$STPKG_ANIMATED_TARGET_FILETYPE - local BONUS_OPT="" + local DEST_EXT=$(file_get_ext_from_type "$DEST_TYPE") + + convert "${FILE}" -coalesce -background none -trim -layers TrimBounds "$DEST_EXT:${TEMP}" 1>&2 \ + && progress_dot \ + || die "$NAME failed trimming the sticker" + convert "${TEMP}" -coalesce -dispose Background -resize ${DEST_WIDTH}x${DEST_HEIGHT} "$DEST_EXT:${TEMP}" 1>&2 \ + && progress_dot \ + || 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 \ + && progress_dot \ + || die "$NAME failed optimizing the sticker" else # # Convert fixed image # local DEST_TYPE=$STPKG_IMAGE_TARGET_FILETYPE - local BONUS_OPT="-trim +repage" - fi + 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 ${BONUS_OPT} -background none -gravity center -resize ${DEST_WIDTH}x${DEST_HEIGHT} "${DEST_EXT}:${TEMP}" 1>&2 \ - && progress_dot \ - || die "$NAME failed converting the sticker" + convert "$FILE" -bordercolor none -border 1 -background none -gravity center -trim +repage -resize ${DEST_WIDTH}x${DEST_HEIGHT} "${DEST_EXT}:${TEMP}" 1>&2 \ + && progress_dot \ + || die "$NAME failed converting the sticker" + fi - DEST_WIDTH=$(file_get_width "$TEMP") - DEST_HEIGHT=$(file_get_height "$TEMP") fi - # TODO: get real width/height from generated file + # TODO: check for gifs here + DEST_WIDTH=$(file_get_width "$TEMP") + DEST_HEIGHT=$(file_get_height "$TEMP") # Upload the transformed file local MXC=$(__upload_file "$DEST_TYPE" "$TEMP" "$NAME") + rm "$TEMP" progress_dot JSON_REF=$(create_sticker_json "$PACK_NAME" "$NAME" "$DEST_WIDTH" "$DEST_HEIGHT" "$DEST_TYPE" "$MXC") -- GitLab