In KDE, if you want to use an image as your user avatar you have to save it as a 64×64 png file and name it .face.icon inside your home directory. But what will you do if you want to use your Gravatar? You’ll have to go to gravatar.com, login with your email and password, download your image, convert it to png format if it’s not already a png, and save it as .face.icon inside your home directory.. this is quite the boring process, but thankfully, the nice guys at Automattic have created an API which allows everyone to retrieve a gravatar image using a simple anonymous GET request.
The BASH way
In order to retrieve our gravatar image, we’ll need an email address to be ashed using md5, then we’ll be able to use wget (or whatever program you want to use) and download the image.
We’ll have to specify the format of the image and the size as well, but the API can deliver everything for us exactly the way we want it. Here’s the code:
wget http://www.gravatar.com/avatar/$(echo -n "email@example.com" | md5sum |cut -d " " -f 1).png?s=64 -O .face.icon
looks confusing? Let me explain:
We said that the Gravatar API requires the email address to be ashed using md5, so in this portion
$(echo -n "firstname.lastname@example.org" | md5sum |cut -d " " -f 1) this is exactly what we did, we gave our email to md5sum which is part of the coreutils package in every linux distro, and we piped it with cut to grab just the ash string without the sum explanation. we used a subshell “
$()” to execute the command and return it’s value in the main shell where we called wget with the -O option to specify the output file name. Using the subshell, this is the url that wget used:
which is the format that the gravatar API is expecting to receive, specifying also the file type and the size of the image with the parameter
s=64. Neat uh?!
That’s it, now if you open the K menu you’ll see your face, same thing will happen when you lock your screen or login into your KDE desktop.
As usual, if you have any questions feel free to drop me a line in the comments section below. 😉