Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

A Google User's profile picture defaults to https://yt3.ggpht.com/-_fExgATRXLY/AAAAAAAAAAI/AAAAAAAAAAA/-fmo8LhN7Pg/s240-c-k-no-rj-c0xffffff/photo.jpghttps://yt3.ggpht.com/-_fExgATRXLY/AAAAAAAAAAI/AAAAAAAAAAA/-fmo8LhN7Pg/s240-c-k-no-rj-c0xffffff/photo.jpg

I want to check to see if a user has updaed their picture to something besides their default based on the URL for the image. Is that possible? Is there another way to check?

EDIT: A URL of a google profile picture that has been set is this: https://yt3.ggpht.com/-zSpYe-dpPNk/AAAAAAAAAAI/AAAAAAAAAAA/EVfQSDPEeQc/s240-c-k-no-rj-c0xffffff/photo.jpg https://yt3.ggpht.com/-zSpYe-dpPNk/AAAAAAAAAAI/AAAAAAAAAAA/EVfQSDPEeQc/s240-c-k-no-rj-c0xffffff/photo.jpg

like image 974
Jonathan Allen Grant Avatar asked Jul 25 '16 19:07

Jonathan Allen Grant


People also ask

Can you change your Google profile picture back to default?

Just head over to Basic info > PROFILE PICTURE and hit the “Remove” button. You'll then see your picture revert to the original alphabet on colored background look almost immediately.

Where is my Google profile picture stored?

Where a user's profile photo is stored. A user's profile photo is stored in their Album Archive, at get.google.com/albumarchive, whether it's added by an admin or the user.


1 Answers

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.

Default Pic1

Default Pic2

like image 118
saurabheights Avatar answered Sep 28 '22 03:09

saurabheights