1
0
mirror of https://github.com/flarum/core.git synced 2025-07-29 04:30:56 +02:00

Add preliminary avatar resizing

This commit is contained in:
Toby Zerner
2015-05-07 13:59:07 +09:30
parent 05a119e99b
commit 04c862f5a3
3 changed files with 216 additions and 155 deletions

View File

@@ -9,6 +9,7 @@ use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemInterface;
use League\Flysystem\MountManager;
use Intervention\Image\ImageManager;
class UploadAvatarCommandHandler
{
@@ -39,6 +40,9 @@ class UploadAvatarCommandHandler
// throw an exception otherwise.
$user->assertCan($command->actor, 'edit');
$manager = new ImageManager(array('driver' => 'imagick'));
$manager->make($command->file->getRealPath())->fit(100, 100)->save();
$filename = $command->file->getFilename();
$uploadName = Str::lower(Str::quickRandom()) . '.jpg';
@@ -56,6 +60,7 @@ class UploadAvatarCommandHandler
event(new AvatarWillBeUploaded($user, $command));
$mount->move("source://$filename", "target://$uploadName");
$user->save();
$this->dispatchEventsFor($user);