| 23 Jul 2021 |
@grahamc:nixos.org | nice! | 15:48:25 |
@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 (he/him) left the room. | 15:49:04 |
CRTified | That's a clean style for a shell script 👀 | 15:50:20 |
CRTified | looks good to go | 15:50:39 |
CRTified | 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 | that is a cool idea | 15:58:25 |
CRTified | I'll try something this evening (so in 2-3 hours probably) | 15:59:12 |
CRTified | * 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 | that would be cool | 16:03:18 |
@grahamc:nixos.org | I'm not going to roll it out widely yet anyway, I want to give some people time to think about it | 16:03:29 |
@grahamc:nixos.org | applied to !gKfPYWNBcIabzMfEvn:nixos.org
!pbdtvoHxUGLhcEvnlu:nixos.org
| 16:04:32 |
@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 |
CRTified | 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 |
CRTified | 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 |
CRTified |  Download image.png | 16:36:30 |
CRTified | The HTTP header is actually perserved across servers 🤔 | 16:36:43 |
CRTified | * The HTTP header is actually perserved across homeservers 🤔 | 16:36:46 |
CRTified |  Download new.png | 17:02:42 |
CRTified | 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 |
CRTified | (Using the nix-snowflake.svg from https://github.com/NixOS/nixos-artwork/tree/master/logo ) | 17:03:29 |
@grahamc:nixos.org | wow! | 17:10:17 |
CRTified | 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 | We should also consider overlaying a word or too if we want to get fancy 🙂 | 17:19:29 |
CRTified |  Download new.png | 17:19:38 |
kevincox | You read my mind :) | 17:19:40 |
CRTified | Would give e.g. this | 17:19:42 |
CRTified | not the prettiest color combination, but it should be easier to identify that way :D | 17:20:07 |
@grahamc:nixos.org | it might "encourage" people to come up with other ones | 17:27:55 |
CRTified | Alternatively one could stick to the nix logo colors for the letter 🤔 | 17:32:46 |