diff --git a/matrixpack.sh b/matrixpack.sh
index cb02c47727f35e5422f076937cf3c21b466e2451..6cc11d54a0819a68de03953b4c8a5092803b5f3e 100755
--- a/matrixpack.sh
+++ b/matrixpack.sh
@@ -31,37 +31,50 @@ homeserver=$2
 echo -e "Creating sticker pack \033[94;1m$packname\033[0m\nhomeserver=\033[94m$homeserver\033[0m\noutput=\033[94m$slug\033[0m"
 
 # Making result folder
-mkdir $slug
+if ! [ -d $slug ]; then mkdir $slug; fi
 echo -n "{\"title\":\"$packname\",\"id\":\"$slug\",\"stickers\":[" > "$slug/$slug.json"
 
-first=0
+first=""
 for f in *
 do
+  # Ignore folders
   if [ -f "$f" ]; then
-    echo -n "$f : trimming and resizing"
-    convert "$f" -bordercolor none -border 1 "$slug/$f.png"
+    echo -n "$f : "
+    type="png"
+    opts="-type TrueColor PNG32:"
+
+    # Gif
+    if [[ "$f" == *.gif ]]; then
+      type="gif"
+      opts=""
+    fi
+    # Trim, resize and remove indexed palette from image
+    echo -n "trimming and resizing"
+    convert "$f" -bordercolor none -border 1 "$slug/$f"
     echo -n "."
-    convert "$slug/$f.png" -trim +repage "$slug/$f.png"
+    convert "$slug/$f" -trim +repage "$slug/$f"
     echo -n "."
-    convert -background none -gravity center "$slug/$f.png" -resize "128x128>" -extent 128x128 "$slug/$f.png"
+    convert -background none -gravity center "$slug/$f" -resize "128x128>" -extent 128x128 $opts"$slug/$f"
     echo -ne ". \033[92mdone\033[0m! "
+    
     # First item in array
-    if test $first != 1 ; then
-      first=1
-      else echo -n "," >> "$slug/$slug.json"
-    fi
-
+    echo -n "$first" >> "$slug/$slug.json"
+    
     # Uploading image
     echo -n "uploading."
-    mxc=$(curl -s -X POST -H "Content-Type: image/png" --data-binary "@$slug/$f.png" "https://$homeserver/_matrix/media/r0/upload?access_token=$token" | python3 -c "import sys, json; print(json.load(sys.stdin)['content_uri'])")
+    mxc=$(curl -s -X POST -H "Content-Type: image/$type" --data-binary "@$slug/$f" "https://$homeserver/_matrix/media/r0/upload?access_token=$token" | python3 -c "import sys, json; print(json.load(sys.stdin)['content_uri'])")
     echo -n "."
+
     # Appending to json
-    echo -n "{\"body\":\"$f\",\"info\":{\"h\":128,\"w\":128,\"thumbnail_url\":\"$mxc\"},\"msgtype\":\"m.sticker\",\"url\":\"$mxc\",\"id\":\"$packname-$f\"}" >> "$slug/$slug.json"
+    echo -n "{\"body\":\"$f\",\"info\":{\"mimetype\":\"image/$type\",\"h\":128,\"w\":128,\"thumbnail_url\":\"$mxc\"},\"msgtype\":\"m.sticker\",\"url\":\"$mxc\",\"id\":\"$packname-$f\"}" >> "$slug/$slug.json"
+    first=","
     echo -e ". \033[92msuccess\033[0m!"
   fi
 done
-montage "$slug/*.png" "$slug/preview.png"
+montage "$slug/*.png" "preview.png"
+rm $slug/*.png
+mv "preview.png" "$slug"
 echo -ne "### $packname  \n![Preview of $packname](preview.png)" > "$slug/README.md"
 echo -n "]}" >> "$slug/$slug.json"
 cd - > /dev/null
-echo -e "\033[92;1mPack successfully created!\nCheck $dir/$slug for output\033[0m"
+echo -e "\033[92;1mPack successfully created!\n\033[0mCheck \033[94;1m$dir/$slug \033[0mfor output"