!GsmxjHfeAYLsTEQmjS:nixos.org

Matrix Meta (Nix)

657 Members
Discuss your proposals for the Matrix space here, before suggesting them in #matrix-suggestions:nixos.org188 Servers

Load older messages


SenderMessageTime
23 Jul 2021
@grahamc:nixos.org@grahamc:nixos.orgnice!15:48:25
@grahamc:nixos.org@grahamc:nixos.org

here is what I've put together:


make_avatar() (
  room_id=$1
  roomhash=$(md5sum <<<"$room_id" | cut -d' ' -f1)
  filename="$scratch/$roomhash.avatar"

  curl "https://www.gravatar.com/avatar/${roomhash}?d=identicon&f=y&s=2048" > "$filename"
  echo "$filename"
)

upload_media() (
  FILEPATH="${1}"

  mime=$(file --brief --mime "$FILEPATH")

  # Upload image to image.png
  curl \
    --silent \
    -H "Content-Type: $mime" \
    -H "Authorization: Bearer ${AUTH_TOKEN}" \
    -X POST \
    --data-binary "@${FILEPATH}" \
    "${HOMESERVER}/_matrix/media/r0/upload?filename=image.png" \
    | jq '.content_uri'
)

set_room_avatar() (
  ROOMID=$1
  MXC=$2

  # Build m.room.avatar event
  EVENT_SET_AVATAR=$(jq -n '{ url: $mxc }' --arg mxc "$MXC")

  # Push event
  curl \
    --silent \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer ${AUTH_TOKEN}" \
    -X PUT \
    --data "${EVENT_SET_AVATAR}" \
    "${HOMESERVER}/_matrix/client/r0/rooms/${ROOMID}/state/m.room.avatar"
)

15:48:52
@jez:petrichor.meJez (he/him) left the room.15:49:04
@schnecfk:ruhr-uni-bochum.deCRTifiedThat's a clean style for a shell script 👀15:50:20
@schnecfk:ruhr-uni-bochum.deCRTifiedlooks good to go15:50:39
@schnecfk:ruhr-uni-bochum.deCRTified grahamc (he/him): maybe keep a list of the rooms that you'll assign a generated image for. That way, we could replace them easier with something prettier (autogenerated) afterwards. I was thinking about doing something with the nix logo, e.g. assigning colors from the hash of the room name or something like this 15:57:24
@grahamc:nixos.org@grahamc:nixos.orgthat is a cool idea15:58:25
@schnecfk:ruhr-uni-bochum.deCRTifiedI'll try something this evening (so in 2-3 hours probably)15:59:12
@schnecfk:ruhr-uni-bochum.deCRTified * I'll try something this evening (so in 2-3 hours probably), but that might help to keep the nix "branding" present in the room avatars 😁15:59:39
@grahamc:nixos.org@grahamc:nixos.orgthat would be cool16:03:18
@grahamc:nixos.org@grahamc:nixos.orgI'm not going to roll it out widely yet anyway, I want to give some people time to think about it16:03:29
@grahamc:nixos.org@grahamc:nixos.orgapplied to !gKfPYWNBcIabzMfEvn:nixos.org !pbdtvoHxUGLhcEvnlu:nixos.org 16:04:32
@grahamc:nixos.org@grahamc:nixos.org hrm I tried to add a URL parameter to the community room's avatar but it breaks the rendering: "avatar": "mxc://nixos.org/721c442bc81f9fedaeada3ad89af693666619889?autogenerated=1" 16:11:43
@schnecfk:ruhr-uni-bochum.deCRTified
In reply to @grahamc:nixos.org
hrm I tried to add a URL parameter to the community room's avatar but it breaks the rendering: "avatar": "mxc://nixos.org/721c442bc81f9fedaeada3ad89af693666619889?autogenerated=1"
I wonder if the mimetype is preserved - in that case you could use a parameter there? 🤔
16:29:12
@schnecfk:ruhr-uni-bochum.deCRTified Looks like it is preserved - both in the event (where you can supply it under the info->mimetype key), and when uploading the image (in that case it's the Content-Type header) 16:36:09
@schnecfk:ruhr-uni-bochum.deCRTifiedimage.png
Download image.png
16:36:30
@schnecfk:ruhr-uni-bochum.deCRTifiedThe HTTP header is actually perserved across servers 🤔16:36:43
@schnecfk:ruhr-uni-bochum.deCRTified * The HTTP header is actually perserved across homeservers 🤔16:36:46
@schnecfk:ruhr-uni-bochum.deCRTifiednew.png
Download new.png
17:02:42
@schnecfk:ruhr-uni-bochum.deCRTified

That's generated by

#! /usr/bin/env nix-shell
#! nix-shell -i sh -p inkscape

val=$(echo "Let's test it" | sha512sum -)
color1=${val:0:3}
color2=${val:4:3}
echo $color1
echo $color2
cat nix-snowflake.svg \
    | sed "s/7EBAE4/${color1}/gi" \
    | sed "s/5277C3/${color2}/gi" \
    | inkscape -z -w 128 --pipe -o new.png
17:02:50
@schnecfk:ruhr-uni-bochum.deCRTified (Using the nix-snowflake.svg from https://github.com/NixOS/nixos-artwork/tree/master/logo ) 17:03:29
@grahamc:nixos.org@grahamc:nixos.orgwow!17:10:17
@schnecfk:ruhr-uni-bochum.deCRTified

If you want to keep some reference to the room name: This will use the first letter of the second word and write it in there, too:

#! /usr/bin/env nix-shell
#! nix-shell -i sh -p inkscape imagemagick

INPUT="Nix Matrix Discussion"
LETTER=$(echo "$INPUT" | awk '{print $2}' | head -c1)

val=$(echo "$INPUT" | sha512sum -)
color1=${val:0:3}
color2=${val:3:3}
color3=${val:6:3}
color4="000"

cat nix-snowflake.svg \
    | sed "s/7EBAE4/${color1}/gi" \
    | sed "s/5277C3/${color2}/gi" \
    | inkscape -z -w 256 --pipe --export-type=png --export-filename=-\
    | convert png:- -font "DejaVu-Sans-Bold" -gravity center \
	      -pointsize 128 -fill "#${color3}" -stroke "#${color4}" -strokewidth 4 -annotate 0 "$LETTER" \
	      new.png
17:19:28
@kevincox:matrix.orgkevincoxWe should also consider overlaying a word or too if we want to get fancy 🙂17:19:29
@schnecfk:ruhr-uni-bochum.deCRTifiednew.png
Download new.png
17:19:38
@kevincox:matrix.orgkevincoxYou read my mind :) 17:19:40
@schnecfk:ruhr-uni-bochum.deCRTifiedWould give e.g. this17:19:42
@schnecfk:ruhr-uni-bochum.deCRTifiednot the prettiest color combination, but it should be easier to identify that way :D17:20:07
@grahamc:nixos.org@grahamc:nixos.orgit might "encourage" people to come up with other ones17:27:55
@schnecfk:ruhr-uni-bochum.deCRTifiedAlternatively one could stick to the nix logo colors for the letter 🤔 17:32:46

Show newer messages


Back to Room ListRoom Version: 6