PHP code example of drago-ex / gravatar

1. Go to this page and download the library: Download drago-ex/gravatar library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

drago-ex / gravatar example snippets


$url = $this->gravatar->getUrl('[email protected]');
$small = $this->gravatar->getUrl('[email protected]', 40);

use Drago\Gravatar\GravatarAdapter;
use Nette\Application\UI\Presenter;

final class ProfilePresenter extends Presenter
{
	use GravatarAdapter;

	protected function beforeRender(): void
	{
		parent::beforeRender();
		// a guest has no identity, so no avatar
		$email = $this->getUser()->getIdentity()?->getData()['email'] ?? null;
		if (is_string($email)) {
			$this->gravatar->setEmail($email);
		}
	}
}

public string $gravatar;
latte
<img n:if="isset($gravatar)" src="{$gravatar}" alt="">