我想把我的文件上传成圆形,但是无法实现。
我看到一些关于给图像应用蒙版的话题,但是当我应用蒙版时,它花费的时间太长了,服务器关闭了该请求。
我正在使用 Laravel 的 Intervention Image
库。
以下是我的代码:
$identifier = "{$this->loggedUser->id}" . str_random(9) . ".{$file->getClientOriginalExtension()}";
$mask = $this->createCircleMask(200, 200);
$thumbMask = $this->createCircleMask(40, 40);
Image::make($file->getRealPath())->mask($mask)->save(public_path("images/profile/{$identifier}"));
Image::make($file->getRealPath())->mask($thumbMask)->save(public_path("images/profile/thumbs/{$identifier}"));
createCircleMask
方法的代码如下:
public function createCircleMask($width, $height)
{
$circle = Image::canvas($width, $height, '#000000');
return $circle->circle($width - 1, $width / 2, $height / 2);
}