AVrAmTAR API
Hello,
We have implemented basic AVrAmTAR API, so you can start using AVrAmTAR in your (web) applications from now on very easy. The base of our API is AVrAmTAR URL, which is built from several parts.
The URL is built from three parts: URL base, email parameter and default image parameter.
http://avatars.avramtar.com/avatar.php
?email=EMAIL_MD5
&default=DEFAULT_IMAGE_URL
- URL base is URL to avatar.php on our website. It is script that will serve avatars to visitors of your web application.
- Email parameter contains md5 hash of user’s email addres. This is required and most important parameter, and with this parameter our script knows which user’s avatars it should serve. So when user registers on your website and leaves his email address, you can instantly display his avatar(s).
- Default image parameter contains URLencoded (full) URL to default avatar, which will be shown ONLY if no avatars are found for provided (hashed) email. This parameter is optional, and if not supplied default no-avatar image will be shown:
To use our API in PHP, you don’t need any external plugins as PHP already contains functions for MD5 hashing and URLencoding.
Example:
-
<?php
-
//AVrAmTAR function, you should edit default value of $default_avatar
-
function get_avramtar($user_email, $default_avatar = ”)
-
{
-
}
-
-
//usage example
-
?>
Note: We suggest that you re-type above code as WordPress may mess up quotes and apostrophes in code, or just download AVrAmTAR API for PHP
Using AVrAmTAR API in Perl is easy, as Perl also supports MD5 hashing and URL encoding. Nenad Vasić provided sample code for Perl:
-
#!/usr/bin/perl
-
-
#AVrAmTAR function
-
sub get_avramtar {
-
$user_email = $_[0];
-
$default_avatar = $_[1];
-
$result = "http://avatars.avramtar.com/avatar.php?email=" . md5_hex($user_email) . "&default=" . uri_escape($default_avatar);
-
return $result;
-
}
-
-
#usage example, first parameter is user’s email address
-
#and second parameter is default avatar url (empty string)
-
#for default no-avatar image
Note: We suggest that you re-type above code as WordPress may mess up quotes and apostrophes in code, or just download AVrAmTAR API for Perl
ASP does not have MD5 support by default, so we’re using code for MD5 digest from freevbcode.com. I wish to thank ES community and it’s supermoderator Shadowed for help on this. Example:
-
<HTML>
-
<!–#include file="md5.asp"–>
-
<%
-
‘AVrAmTAR function
-
Public function get_avramtar(user_email, default_avatar)
-
result = "http://avatars.avramtar.com/avatar.php?email=" & md5(user_email)
-
if default_avatar <> "" then result = result & "&default=" & Server.URLEncode(default_avatar)
-
return result
-
end function
-
-
‘usage example, first parameter is user’s email address
-
‘and second parameter is default avatar url (empty string)
-
‘for default no-avatar image
-
response.write "<img src=’" & get_avramtar("user@domain.com","") & "’ />"
-
%>
-
</HTML>
Note: We suggest that you re-type above code as WordPress may mess up quotes and apostrophes in code, or just download AVrAmTAR API for ASP
Shadowed also provided code for ASP.NET/VisualBasic:
-
<%@ Page Language="VB" AutoEventWireup="false" %>
-
<%@ Import Namespace="System.Security.Cryptography" %>
-
<script runat="server">
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
imgAvramtar.ImageUrl = get_avramtar("user@domain.com", "")
-
End Sub
-
Private Function get_avramtar(ByVal user_email As String, ByVal default_avatar As String) As String
-
Dim MD5Hasher As MD5 = MD5.Create()
-
Dim data() As Byte = MD5Hasher.ComputeHash(Encoding.Default.GetBytes(user_email))
-
Dim MyBuilder As New System.Text.StringBuilder()
-
Dim i As Integer
-
Dim result As String
-
For i = 0 To data.Length – 1
-
MyBuilder.Append(data(i).ToString("x2"))
-
Next
-
result = "http://avatars.avramtar.com/avatar.php?email=" & MyBuilder.ToString()
-
If default_avatar <> "" Then result &= "&default=" & System.Web.HttpUtility.UrlEncode(default_avatar)
-
Return result
-
End Function
-
</script>
-
<html>
-
<body>
-
<asp:Image ID="imgAvramtar" runat="server" />
-
</body>
-
</html>
Note: We suggest that you re-type above code as WordPress may mess up quotes and apostrophes in code, or just download AVrAmTAR API for ASP.NET/vb
Dejan Simić provided plugin for Rails, and it can be installed from svn:
ruby script/plugin install svn://rors.org/avramtar
Example of usage:
-
<%= avramtar_img ‘user@domain.com’ %>
To change default avatar (one that is shown when no original avatar can be found), override default_avatar function in ApplicationHelper like this:
-
module ApplicationHelper
-
def default_avatar
-
‘http://www.domain.com/default-avatar.png’
-
end
-
end
Usage in…
More languages soon… maybe