keitharm / wdR-contribution

wdR contribution score calculator and signature generator
1 stars 0 forks source link

Avatar Images #3

Closed keitharm closed 11 years ago

keitharm commented 11 years ago

We need to find a way to make it so that if a user doesn't have an avatar image on Gravatar, it needs to default to the wdR default profile image.

For some reason, the URLs for the profile images display properly in html but are extracted weirdly in PHP.

I don't know what the issue is, will have to do further investigating.

ghost commented 11 years ago

I noticed this. I was thinking of just saving the default image to the package, and then checking if the user is using the default. If so, the script will just access the local copy. But yeah, there's some issue there that I couldn't figure out.

keitharm commented 11 years ago

Yeah, we'll have to do something like that.

The format of the URL (your profile in this example) looks like this: http://www.gravatar.com/avatar/9475e56ba72f3baea98c41e4fe4eb49d? s=100&d=http%3A%2F%2Fwebdevrefinery.com%2Fforums%2Fpublic%2Fstyle_images%2FC ielo%2Fprofile%2Fdefault_large.png

It looks like the "http://www.gravatar.com/avatar/9475e56ba72f3baea98c41e4fe4eb49d? s=100" part is the user's avatar on gravatar and the s $_GET variable is just the height & width.

And then the "http%3A%2F%2Fwebdevrefinery.com%2Fforums%2Fpublic%2Fstyle_images%2FC ielo%2Fprofile%2Fdefault_large.png" is the default image to put in place if the gravatar account doesn't have an image.

So, I think what we might be able to extract the gravatar image from the profile image url and compare that image to the default gravatar logo placeholder image. If there is a match, then display the wdR default image or else display the gravatar image.

ghost commented 11 years ago

Yep sounds good.

keitharm commented 11 years ago

Fixed!

// Original unmodified avatar URL $avatar = $data->avatar; if (strpos($avatar, "gravatar.com") !== false) { // Extract gravatar image $avatar = substr($avatar, 0, 69); if (file_get_contents($avatar) == file_get_contents("default.jpg")) { $avatar = "http://i2.wp.com/webdevrefinery.com/forums/public/style_images/Cielo/profile/default_large.png"; } }

That turned out to be a lot easier than I thought it would be. Never would have thought comparing two images via file_get_contents would have worked lol :)

ghost commented 11 years ago

Easy! Yeah, I love how PHP handles images. You can file_get_contents an image, then turn it back into an image with imagefromstring(). Love it!