mirror of
https://github.com/flarum/framework.git
synced 2025-02-21 10:42:46 +08:00
Support PNG avatars with transparent backgrounds and fix EXIF rotation (#1168)
As `orientate` requires the EXIF extension, we can only call it if the extension is installed. Fixes #1161 and #1163.
This commit is contained in:
parent
14d925fa02
commit
76775d58c8
@ -173,7 +173,7 @@ class RegisterUserHandler
|
||||
'target' => $this->uploadDir,
|
||||
]);
|
||||
|
||||
$uploadName = Str::lower(Str::quickRandom()).'.jpg';
|
||||
$uploadName = Str::lower(Str::quickRandom()).'.png';
|
||||
|
||||
$user->changeAvatarPath($uploadName);
|
||||
|
||||
|
@ -100,8 +100,13 @@ class UploadAvatarHandler
|
||||
|
||||
$manager = new ImageManager;
|
||||
|
||||
// Explicitly tell Intervention to encode the image as JSON (instead of having to guess from the extension)
|
||||
$encodedImage = $manager->make($tmpFile)->orientate()->fit(100, 100)->encode('jpg', 100);
|
||||
// Explicitly tell Intervention to encode the image as PNG (instead of having to guess from the extension)
|
||||
// Read exif data to orientate avatar only if EXIF extension is enabled
|
||||
if (extension_loaded('exif')) {
|
||||
$encodedImage = $manager->make($tmpFile)->orientate()->fit(100, 100)->encode('png', 100);
|
||||
} else {
|
||||
$encodedImage = $manager->make($tmpFile)->fit(100, 100)->encode('png', 100);
|
||||
}
|
||||
file_put_contents($tmpFile, $encodedImage);
|
||||
|
||||
$this->events->fire(
|
||||
@ -117,7 +122,7 @@ class UploadAvatarHandler
|
||||
$mount->delete($file);
|
||||
}
|
||||
|
||||
$uploadName = Str::lower(Str::quickRandom()).'.jpg';
|
||||
$uploadName = Str::lower(Str::quickRandom()).'.png';
|
||||
|
||||
$user->changeAvatarPath($uploadName);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user