Gravatar avatar image URLs that are the default image will return a 404 Not Found
error if the following parameter is set d=404
. For example, here are the URLs that you used as examples, but with the parameter set:
http://www.gravatar.com/avatar/19b2990ba88512ab38abdbbca5701d27?s=120&d=404
http://www.gravatar.com/avatar/88a771dc1a611b2038c9a0ad0770b595?s=120&d=404
http://www.gravatar.com/avatar/d8f98df8a6ed24a727b993ea01cc91f6?s=120&d=404
Assuming you're detecting if the images default using JavaScript, you can then use AJAX (without displaying the image) or an error catcher (displaying non-default images) to detect if these images successfully loaded.
jQuery (AJAX)
// Image Exists
$.ajax({url:"http://www.gravatar.com/avatar/d8f98df8a6ed24a727b993ea01cc91f6?s=120&d=404",type:"GET",crossDomain:true,success:(function(){console.log("Custom Gravatar");}),error:(function(){console.log("Default Gravatar");})});
// Image Does Not Exist
$.ajax({url:"http://www.gravatar.com/avatar/88a771dc1a611b2038c9a0ad0770b595?s=120&d=404",type:"GET",crossDomain:true,success:(function(){console.log("Custom Gravatar");}),error:(function(){console.log("Default Gravatar");})});
Error Catching
You can use either the jQuery load
and error
event handlers, or the HTML onload
and onerror
attributes.
$("img").load(function(e) {
e.target.parentNode.parentNode.getElementsByClassName("stat")[0].innerHTML = e.type;
}).error(function(e) {
e.target.parentNode.parentNode.getElementsByClassName("stat")[0].innerHTML = e.type;
});
table,
td {
border: 1px solid black;
border-collapse: collapse;
}
table img {
width: 48px;
height: 48px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tbody>
<tr>
<td>Image</td>
<td>Expected Result</td>
<td>Actual Result</td>
</tr>
<tr>
<td>
<img id="good" src="http://www.gravatar.com/avatar/d8f98df8a6ed24a727b993ea01cc91f6?s=120&d=404" />
</td>
<td>load</td>
<td class="stat">Loading...</td>
</tr>
<tr>
<td>
<img id="bad" src="http://www.gravatar.com/avatar/88a771dc1a611b2038c9a0ad0770b595?s=120&d=404" />
</td>
<td>error</td>
<td class="stat">Loading...</td>
</tr>
</tbody>
</table>
EDIT: OP clarified what was being asked for
I wrote a small VBA script in this example file to iterate through the first column up until the first empty cell, creating WinHTTP requests with a modified URL then, as OP asked, deleting the contents of cells that contained a link to the default Gravatar avatar.
To run the code in the sample Excel file:
- Excel 2003 and lower: Tools > Macro > Macros (Alt + F8) > checkGravatar
- Excel 2007 and newer: Develooper > Macros > checkGravatar
In order to run the VBA, you may also need to enable macros and reference MSXML.
Sub checkGravatar()
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
Dim URL As String
Dim goodStat As String
Dim badStat As String
Dim row As Integer
Dim pos As Integer
row = 1
URL = Cells(row, 1).Value
Do While Len(URL) > 0
If InStr(URL, "gravatar.com/avatar/") > 0 Then
If InStr(URL, "?") = 0 Then
URL = URL & "?d=404"
Else
If Not InStr(URL, "&d=") Then
URL = URL & "&d=404"
End If
End If
objHTTP.Open "GET", URL, False
objHTTP.send ("")
If objHTTP.Status = 404 Then
Cells(row, 1).Value = ""
Else
MsgBox "GET request failed"
End If
row = row + 1
URL = Cells(row, 1).Value
Loop
End Sub