How can I programmatically check if a Google User’s profile picture isn’t default?

Solution using Google API In Google response, it provides a field isDefault which is set to false if user has uploaded his/her pic. You can check the documentation and try the sample api here.

You can just add userId as me and set field value to image to try the example. A sample value returned is:-

{
 "image": {
  "url": "https://lh3.googleusercontent.com/-cXXaVVq8nMM/AAAAAAAAAAI/AAAAAAAAAKI/_Y1WfBiSnRI/photo.jpg?sz=50",
  "isDefault": false
 }
}

Solution using Image Processing

Being an Image Processing Engineer, here is another solution. A simple similarity/difference metrics computed between a sample Google default Image and the downloaded image can easily solve this problem. I have found Google to change the default picture over past year. Though the images look the same, the pixels do not match perfectly. Thus, normalised error should be close to Zero, but may not always be Zero.

Using ImageMagick

Imagemagick is a bash command Image Processing Utility(Well its a lot more…). One can quickly check if the image is default image using below commands:-

Root Mean Square Error(the smaller, the better):

$> compare -metric RMSE defaultProfilePic1.jpg defaultProfilePic2.jpg NULL:
$> 242.453 (0.0036996)

In above command, NULL represents directing the output to console. The output in parentheses is the normalised error, which as you can see is close to 0. A threshold of 0.01-0.03, should be good enough to start.

Normalized Cross Correlation(the closer to 1, the better):

Vice-versa, one can use similarity metrics to see if normalized output is close enough to 1.

$> compare defaultProfilePic1.jpg defaultProfilePic2.jpg -metric NCC NULL:
$> 0.998602

For more information, see here.

Here are the sample images downloaded using Google Api.

Leave a Comment