mirror of
https://github.com/flarum/core.git
synced 2025-07-18 15:21:16 +02: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:
@@ -173,7 +173,7 @@ class RegisterUserHandler
|
|||||||
'target' => $this->uploadDir,
|
'target' => $this->uploadDir,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$uploadName = Str::lower(Str::quickRandom()).'.jpg';
|
$uploadName = Str::lower(Str::quickRandom()).'.png';
|
||||||
|
|
||||||
$user->changeAvatarPath($uploadName);
|
$user->changeAvatarPath($uploadName);
|
||||||
|
|
||||||
|
@@ -100,8 +100,13 @@ class UploadAvatarHandler
|
|||||||
|
|
||||||
$manager = new ImageManager;
|
$manager = new ImageManager;
|
||||||
|
|
||||||
// Explicitly tell Intervention to encode the image as JSON (instead of having to guess from the extension)
|
// Explicitly tell Intervention to encode the image as PNG (instead of having to guess from the extension)
|
||||||
$encodedImage = $manager->make($tmpFile)->orientate()->fit(100, 100)->encode('jpg', 100);
|
// 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);
|
file_put_contents($tmpFile, $encodedImage);
|
||||||
|
|
||||||
$this->events->fire(
|
$this->events->fire(
|
||||||
@@ -117,7 +122,7 @@ class UploadAvatarHandler
|
|||||||
$mount->delete($file);
|
$mount->delete($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
$uploadName = Str::lower(Str::quickRandom()).'.jpg';
|
$uploadName = Str::lower(Str::quickRandom()).'.png';
|
||||||
|
|
||||||
$user->changeAvatarPath($uploadName);
|
$user->changeAvatarPath($uploadName);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user