mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +02:00
Use a svg file as default user avatar instead of SVG. Also changed path generation logic
This should also fix the path issue described in issue #446
This commit is contained in:
parent
e2437d4c33
commit
bcaf96ed59
3 changed files with 19 additions and 21 deletions
Binary file not shown.
Before Width: | Height: | Size: 18 KiB |
1
public/img/default_avatar.svg
Normal file
1
public/img/default_avatar.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"><g id="Ebene1"><rect x="0.021" y="-0.023" width="19.977" height="20" style="fill:#95bbdf;"/></g><path d="M10,10c2.194,0 4,-1.806 4,-4c0,-2.194 -1.806,-4 -4,-4c-2.194,0 -4,1.806 -4,4c0,2.194 1.806,4 4,4Zm-1.428,1.5c-3.078,0 -5.572,2.494 -5.572,5.572c0,0.512 0.416,0.928 0.928,0.928l12.144,0c0.512,0 0.928,-0.416 0.928,-0.928c0,-3.078 -2.494,-5.572 -5.572,-5.572l-2.856,0Z" style="fill:#fff;fill-rule:nonzero;"/></svg>
|
After Width: | Height: | Size: 856 B |
|
@ -20,9 +20,9 @@ declare(strict_types=1);
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Services\UserSystem;
|
||||
|
||||
use Imagine\Exception\RuntimeException;
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Entity\Attachments\UserAttachment;
|
||||
|
@ -30,16 +30,23 @@ use App\Entity\UserSystem\User;
|
|||
use App\Services\Attachments\AttachmentSubmitHandler;
|
||||
use App\Services\Attachments\AttachmentURLGenerator;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Liip\ImagineBundle\Service\FilterService;
|
||||
use Symfony\Component\Asset\Packages;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
|
||||
class UserAvatarHelper
|
||||
{
|
||||
public const IMG_DEFAULT_AVATAR_PATH = '/img/default_avatar.png';
|
||||
/**
|
||||
* Path to the default avatar image (must not start with a slash, or the asset package will not work)
|
||||
*/
|
||||
public const IMG_DEFAULT_AVATAR_PATH = 'img/default_avatar.svg';
|
||||
|
||||
public function __construct(private readonly bool $use_gravatar, private readonly Packages $packages, private readonly AttachmentURLGenerator $attachmentURLGenerator, private readonly FilterService $filterService, private readonly EntityManagerInterface $entityManager, private readonly AttachmentSubmitHandler $submitHandler)
|
||||
{
|
||||
public function __construct(
|
||||
private readonly bool $use_gravatar,
|
||||
private readonly Packages $packages,
|
||||
private readonly AttachmentURLGenerator $attachmentURLGenerator,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly AttachmentSubmitHandler $submitHandler
|
||||
) {
|
||||
}
|
||||
|
||||
|
||||
|
@ -78,14 +85,9 @@ class UserAvatarHelper
|
|||
return $this->getGravatar($user, 50); //50px wide picture
|
||||
}
|
||||
|
||||
try {
|
||||
//Otherwise we can serve the relative path via Asset component
|
||||
return $this->filterService->getUrlOfFilteredImage(self::IMG_DEFAULT_AVATAR_PATH, 'thumbnail_xs');
|
||||
} catch (RuntimeException) {
|
||||
//If the filter fails, we can not serve the thumbnail and fall back to the original image and log an warning
|
||||
//Otherwise serve the default image (its an SVG, so we dont need to thumbnail it)
|
||||
return $this->packages->getUrl(self::IMG_DEFAULT_AVATAR_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
public function getAvatarMdURL(User $user): string
|
||||
{
|
||||
|
@ -100,14 +102,9 @@ class UserAvatarHelper
|
|||
return $this->getGravatar($user, 150);
|
||||
}
|
||||
|
||||
try {
|
||||
//Otherwise we can serve the relative path via Asset component
|
||||
return $this->filterService->getUrlOfFilteredImage(self::IMG_DEFAULT_AVATAR_PATH, 'thumbnail_xs');
|
||||
} catch (RuntimeException) {
|
||||
//If the filter fails, we can not serve the thumbnail and fall back to the original image and log an warning
|
||||
//Otherwise serve the default image (its an SVG, so we dont need to thumbnail it)
|
||||
return $this->packages->getUrl(self::IMG_DEFAULT_AVATAR_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue