Skip to content
Extraits de code Groupes Projets
Vérifiée Valider d2c7691c rédigé par Kubat's avatar Kubat
Parcourir les fichiers

More functions (for the size, etc) for pictures to divide the work

parent 61398861
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -154,6 +154,21 @@ validate_token() { ...@@ -154,6 +154,21 @@ validate_token() {
info "Token is valid on homeserv '$STPKG_HOMESERV'" info "Token is valid on homeserv '$STPKG_HOMESERV'"
} }
file_get_width() {
local WIDTH=$(identify -format "%w" "$1") >/dev/null
local WIDTH=$(( $WIDTH > 256 ? 256 : $WIDTH ))
echo "$WIDTH"
}
file_get_height() {
local HEIGHT=$(identify -format "%h" "$1") >/dev/null
local HEIGHT=$(( $HEIGHT > 256 ? 256 : $HEIGHT ))
echo "$HEIGHT"
}
file_get_type() { [[ "$1" =~ .*\.gif ]] && echo 'gif' || echo 'png'; }
file_get_name() { echo "$1" | cut -f1 -d'.'; }
upload_file() { upload_file() {
local TYPE=$1 # The type of file (png/gif) local TYPE=$1 # The type of file (png/gif)
local FILE=$2 # The file local FILE=$2 # The file
...@@ -543,7 +558,6 @@ __list() { ...@@ -543,7 +558,6 @@ __list() {
__edit() { __edit() {
# <pack name> <add|del> <sticker> [image file to use] # <pack name> <add|del> <sticker> [image file to use]
die "Not implemented yet"
local PACK_NAME="$1" local PACK_NAME="$1"
local ACTION="$2" local ACTION="$2"
local STICKER_NAME="$3" local STICKER_NAME="$3"
...@@ -559,12 +573,21 @@ __edit() { ...@@ -559,12 +573,21 @@ __edit() {
case "$ACTION" in case "$ACTION" in
add) add)
[ $# -eq 0 ] && die "You must specify an image file for the add action" [ $# -eq 0 ] && die "You must specify an image file for the add action"
jq "del(.stickers[] | select(.body == \"$STICKER_NAME\"))" < "$TEMP" | sponge "$TEMP"
# jq ".stickers += [{\"$STICKER_NAME\"}]" < $TEMP | sponge $TEMP
# TODO: # TODO:
# - Create the sticker from the picture (resize, etc) # - Create the sticker from the picture (resize, etc)
# - Upload to homeserver # - Upload to homeserver
# - Create the json object and add it to the pack's json # - Create the json object and add it to the pack's json
local FILE="$1"
[ ! -r "$FILE" ] && die "Failed to find file '$FILE'"
# Get sizes (see __pack)
local WIDTH=$(file_get_width "$FILE")
local HEIGHT=$(file_get_height "$FILE")
local TYPE=$(file_get_type "$FILE")
local NAME=$(file_get_name "$FILE")
jq "del(.stickers[] | select(.body == \"$STICKER_NAME\"))" < "$TEMP" | sponge "$TEMP"
# jq ".stickers += [{\"$STICKER_NAME\"}]" < $TEMP | sponge $TEMP
;; ;;
del) del)
[ $# -ne 0 ] && die "Extra argument are present: $*" [ $# -ne 0 ] && die "Extra argument are present: $*"
...@@ -669,14 +692,12 @@ __pack() { ...@@ -669,14 +692,12 @@ __pack() {
# if the stderr of stpkg is redirected, progress messages will be lost. # if the stderr of stpkg is redirected, progress messages will be lost.
# Get sizes # Get sizes
local WIDTH=$( identify -format "%w" "$FILE") >/dev/null local WIDTH=$(file_get_width "$FILE")
local HEIGHT=$(identify -format "%h" "$FILE") >/dev/null local HEIGHT=$(file_get_height "$FILE")
local WIDTH=$(( $WIDTH > 256 ? 256 : $WIDTH ))
local HEIGHT=$(( $HEIGHT > 256 ? 256 : $HEIGHT ))
# Get the names and extentions # Get the names and extentions
local TYPE=`[[ "$FILE" =~ .*\.gif ]] && echo 'gif' || echo 'png'` local TYPE=$(file_get_type "$FILE")
local NAME=`echo "$FILE" | cut -f1 -d'.'` local NAME=$(file_get_name "$FILE")
local DEST="$DEST_FOLDER/$NAME.$TYPE" local DEST="$DEST_FOLDER/$NAME.$TYPE"
# For the progress # For the progress
...@@ -689,8 +710,8 @@ __pack() { ...@@ -689,8 +710,8 @@ __pack() {
# Add a ',' only if it's not the first in the array # Add a ',' only if it's not the first in the array
echo -n "$FIRST_IN_ARRAY" >> $DEST_INDEX echo -n "$FIRST_IN_ARRAY" >> $DEST_INDEX
# Upload # Upload the transformed file
upload_file "$TYPE" "$FILE" "$NAME" upload_file "$TYPE" "$DEST" "$NAME"
progress_dot progress_dot
# Calculate the 128x128 format # Calculate the 128x128 format
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter