Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot or tool for creating sticker packs #11

Closed
tulir opened this issue Sep 5, 2020 · 1 comment
Closed

Bot or tool for creating sticker packs #11

tulir opened this issue Sep 5, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@tulir
Copy link
Member

tulir commented Sep 5, 2020

In addition to telegram import, there should be some easy way to create new sticker packs.

Somewhat related to #7

@tulir tulir added the enhancement New feature or request label Sep 5, 2020
@Tigriz
Copy link

Tigriz commented Sep 12, 2020

I created a simple bash script for my use to generate sticker packs automatically.
The output of it is a folder containing a json of uploaded images in current folder, a readme containing a preview and the preview image generated with imagemagick (to be shared on git repos).
However, that's not clean code, it's kinda hardcoded (ex width/height fixed, some infos missing in json, mimetype etc.) but it doesn't affect element when using it.

#!/bin/bash
# usage
# matrixpack token homeserver
# 
# pack name is the folder name
# sticker name is the file name
# /!\ token is sensitive information

if test $# != 2 ; then
  echo 1>&2 "$0:FATAL: $# invalid argument number (expected 2)"
  exit 1
fi

dir=$(pwd)
token=$1
packname=${dir##*/}
homeserver=$2

echo -e "Creating sticker pack\ndir=$dir\npackname=$packname"

json="{\"title\":\"$packname\",\"id\":\"$packname\",\"stickers\":["
first=0
for f in *
do
  if test $first != 1 ; then
    first=1
  else json="$json,"
  fi
  mxc=$(curl -X POST -H "Content-Type: image/png" --data-binary "@$f" "https://$homeserver/_matrix/media/r0/upload?access_token=$token" | python3 -c "import sys, json; print(json.load(sys.stdin)['content_uri'])")
  json="$json{\"body\":\"$f\",\"info\":{\"h\":128,\"w\":128,\"thumbnail_url\":\"$mxc\"},\"msgtype\":\"m.sticker\",\"url\":\"$mxc\",\"id\":\"$f\"}"
done
montage * "preview.png"
mkdir "$packname"
mv "preview.png" "$packname"
echo -e "### $packname  \n![Preview of $packname](preview.png)" > "$packname/README.md"
echo -n "$json]}" > "$packname/$packname.json"

@tulir tulir closed this as completed in 80bcf6d Sep 13, 2020
lxndrbnsv added a commit to lxndrbnsv/stickerpicker that referenced this issue May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants