Kano's Honk getavatar Script

published: [nandalism home] (dark light)


This script/hack is only for importing mastodon user avatars and is very brittle since it depends on the html format of mastodon user pages. It also works, and is quite handy. This script is intended for use with the honk extension outlined in honk avatars are perfect.

You will need ImageMagick or GraphicsMagick installed.

How To Get Mastodon Avatar Images Automatically

usage: ./getavatar https://mastodon.social/users/santaclaus

This will produce a jpg image file in your $datadir/db/memes/ directory where it will be picked up by the honk extension.

The Code

In the script below change $avatarimg to match your $datadir path. Change [gm convert] to [convert] if you are using ImageMagick not GraphicsMagick.

$ cat getavatar
if [ $# != 1 ]; then
  echo "usage: $0 https://mastodon.social/users/santaclaus"
  exit 1
username=`basename $userpath | cut -d@ -f2`
imgurl=`curl -s "$userpath" | egrep '^<meta.*(jpg|jpeg|png|webp)"' | cut -d\" -f 2`
imgbase=`basename $imgurl`
curl -s "$imgurl" >/tmp/$imgbase
gm convert /tmp/$imgbase -resize 64x64! $avatarimg
rm /tmp/$imgbase
iam=`id -u`
if [ $iam -eq 0 ]; then
  chown honk:honk $avatarimg

site built using mf technology