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:
Zeokat 2017-05-10 21:23:08 +02:00 committed by Franz Liedke
parent 14d925fa02
commit 76775d58c8
2 changed files with 9 additions and 4 deletions

View File

@ -173,7 +173,7 @@ class RegisterUserHandler
'target' => $this->uploadDir,
]);
$uploadName = Str::lower(Str::quickRandom()).'.jpg';
$uploadName = Str::lower(Str::quickRandom()).'.png';
$user->changeAvatarPath($uploadName);

View File

@ -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);