1. Go to this page and download the library: Download tourze/user-avatar-bundle 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/ */
use Tourze\UserAvatarBundle\Service\AvatarServiceInterface;
class UserController
{
public function __construct(
private AvatarServiceInterface $avatarService
) {}
public function show(UserInterface $user): Response
{
// Get user avatar URL with default size (128px)
$avatarUrl = $this->avatarService->getLink($user);
// Get user avatar URL with custom size
$largeAvatarUrl = $this->avatarService->getLink($user, 256);
// Handle null user (returns default avatar)
$defaultAvatarUrl = $this->avatarService->getLink(null);
return $this->render('user/show.html.twig', [
'user' => $user,
'avatar_url' => $avatarUrl,
'large_avatar_url' => $largeAvatarUrl,
]);
}
}
use Symfony\Component\Security\Core\User\UserInterface;
class User implements UserInterface
{
/**
* Get user's custom avatar URL
*/
public function getAvatar(): ?string
{
return $this->avatar;
}
/**
* Get user's email for Gravatar
*/
public function getEmail(): ?string
{
return $this->email;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.