PHP Classes

oGravatar: Get avatar images and the profile of Gravatar user

Recommend this page to a friend!
  Info   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (4 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 205 This week: 1All time: 8,408 This week: 350Up
Version License PHP version Categories
ogravatar 1.0MIT/X Consortium ...5.4PHP 5, Graphics, Web services
Description 

Author

This class can get avatar images and the profile of Gravatar user.

It can return the URL of a user with avatar images in the Gravatar site.

The class can also send HTTP requests to the Gravatar API Web server to get user profile information.

Picture of Andre Roque Filipe
  Performance   Level  
Name: Andre Roque Filipe <contact>
Classes: 9 packages by
Country: Portugal Portugal
Innovation award
Innovation award
Nominee: 2x

Details

oGravatar <a href="https://www.gittip.com/ReiDuKuduro/" target="__blank" alt="ReiDuKuduro @gittip" ><img alt="ReiDuKuduro @gittip" src="http://bottlepy.org/docs/dev/_static/Gittip.png" /></a> ========= Simple class that provides easy gravatar integration #Getting the avatar First you need to create a oGravatar object, see below: $my_gravatar = new oGravatar('andre.r.flip@gmail.com'); If you want to use a secure connection, you'll need to pass `true` as second parameter. Now that you have the object created, you can set the some properties like the image size, rating and a default image, in case of a non Gravatar account. ##Image Size Simply use the `setSize` function and use an integer greater than 1 and less than 2048 for the pixel size. $my_gravatar->setSize(200); ##Image Rating The function you need is `setRating` and you can use one of the following constants to simplify your life: - `oGravatar::RATING_G` - `oGravatar::RATING_PG` - `oGravatar::RATING_R` - `oGravatar::RATING_X` Just like this: $my_gravatar->setRating(oGravatar::RATING_X); ##Default Image As you can imagine, my creativity isn't that great, I called this function `setDefault`, you can either set the image path, that you want to define as default, or use one of the following constants: - `oGravatar::DEFAULT_404` - `oGravatar::DEFAULT_MM` - `oGravatar::DEFAULT_IDENTICON` - `oGravatar::DEFAULT_MONSTERID` - `oGravatar::DEFAULT_WAVATAR` Well, you know… $my_gravatar->setDefault(oGravatar::DEFAULT_MONSTERID); ##It's avatar time!! Now that you know how to set some properties, you can get the image, to get the URL. $my_gravatar->getAvatarUrl(); //http://en.gravatar.com/avatar/c34fd2d73a25fabf0bf9ef8f85dbae42?s=200&r=x&d=monsterid If you dont want to loose time writing the HTML, you can do it this way: $attributes = array( 'id' => 'my_gravatar_image', 'class' => 'some_random_class or-not', 'style' => 'height: 200px', 'width' => '200px' ); $my_gravatar->getAvatar($attibutes); //<img src="http://en.gravatar.com/avatar/c34fd2d73a25fabf0bf9ef8f85dbae42?s=200&r=x&d=monsterid" id="my_gravatar_image" class="some_random_class or-not" style="height: 200px" width="200px" /> #Getting the profile info If you want to request the profile info simply call `$my_gravatar->getProfile();`, once you do that, you can check if they email you are using has a profile by doing something like this: if ($my_gravatar->has_profile) { echo '<pre>'; print_r($my_gravatar); echo '</pre>'; } else { echo "This email doesn't have a gravatar account"; } #But wait there is more… … you can chain the functions, watch it: echo $my_gravatar->setSize(200) ->setRating(oGravatar::RATING_X) ->setDefault(oGravatar::DEFAULT_MONSTERID) ->getAvatar($attributes);

  Files folder image Files  
File Role Description
Files folder imageexceptions (4 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Plain text file oGravatar.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  exceptions  
File Role Description
  Plain text file oGravatarInvalidEmailException.php Class Auxiliary script
  Plain text file oGravatarInvalidRatingException.php Class Auxiliary script
  Plain text file oGravatarInvalidSizeException.php Class Auxiliary script
  Plain text file oGravatarRequestFailedException.php Class Auxiliary script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:205
This week:1
All time:8,408
This week:350Up