mirror of
https://github.com/flarum/framework.git
synced 2025-02-21 13:08:13 +08:00
Merge remote-tracking branch 'upstream/1.0.5'
This commit is contained in:
commit
d2fed4989f
@ -9,9 +9,13 @@
|
||||
|
||||
namespace Flarum\Api\Controller;
|
||||
|
||||
use Flarum\Foundation\ValidationException;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Illuminate\Contracts\Filesystem\Factory;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class UploadFaviconController extends UploadImageController
|
||||
{
|
||||
@ -19,6 +23,22 @@ class UploadFaviconController extends UploadImageController
|
||||
|
||||
protected $filenamePrefix = 'favicon';
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
* @param SettingsRepositoryInterface $settings
|
||||
* @param Factory $filesystemFactory
|
||||
*/
|
||||
public function __construct(SettingsRepositoryInterface $settings, Factory $filesystemFactory, TranslatorInterface $translator)
|
||||
{
|
||||
parent::__construct($settings, $filesystemFactory);
|
||||
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -27,18 +47,24 @@ class UploadFaviconController extends UploadImageController
|
||||
$this->fileExtension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
|
||||
|
||||
if ($this->fileExtension === 'ico') {
|
||||
$encodedImage = $file->getStream();
|
||||
} else {
|
||||
$manager = new ImageManager();
|
||||
|
||||
$encodedImage = $manager->make($file->getStream())->resize(64, 64, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
})->encode('png');
|
||||
|
||||
$this->fileExtension = 'png';
|
||||
// @todo remove in 2.0
|
||||
throw new ValidationException([
|
||||
'message' => strtr($this->translator->trans('validation.mimes'), [
|
||||
':attribute' => 'favicon',
|
||||
':values' => 'jpeg,png,gif,webp',
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
$manager = new ImageManager();
|
||||
|
||||
$encodedImage = $manager->make($file->getStream())->resize(64, 64, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
})->encode('png');
|
||||
|
||||
$this->fileExtension = 'png';
|
||||
|
||||
return $encodedImage;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user