Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 干预图像圆角上传_Php_Image_Laravel_Laravel 5_Intervention - Fatal编程技术网

Php 干预图像圆角上传

Php 干预图像圆角上传,php,image,laravel,laravel-5,intervention,Php,Image,Laravel,Laravel 5,Intervention,我试图上传我的文件作为圆圈,但我不能使它工作。 我已经看过一些关于对图像应用掩码的主题,但是当我应用掩码时,它会占用很长的时间,服务器会关闭请求 我正在使用Laravel的干预图像库 我的代码如下: $identifier = "{$this->loggedUser->id}" . str_random(9) . ".{$file->getClientOriginalExtension()}"; $mask = $this->createCircleMask(200, 2

我试图上传我的文件作为圆圈,但我不能使它工作。 我已经看过一些关于对图像应用掩码的主题,但是当我应用掩码时,它会占用很长的时间,服务器会关闭请求

我正在使用Laravel的干预图像库

我的代码如下:

$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}"));
createCircleTask
方法如下所示:

public function createCircleMask($width, $height)
{
    $circle = Image::canvas($width, $height, '#000000');
    return $circle->circle($width - 1, $width / 2, $height / 2);
}

这里有一个在我的例子中有效的函数。但是仅当我使用imagick驱动程序时。标准gd库非常慢,至少在我的测试计算机上是这样。 您可以查看vendor\intervention\image\src\intervention\image\Gd\Commands\MaskCommand.php以了解原因

public function upload() {

    $path = storage_path('app')."/";

    $image = \Image::make(\Input::file('image'));
    $image->encode('png');

    /* if you want to have a perfect and complete circle using the whole width and height the image
     must be shaped as as square. If your images are not guaranteed to be a square maybe you could
     use Intervention's fit() function */
    //  $image->fit(300,300);

    // create empty canvas
    $width = $image->getWidth();
    $height = $image->getHeight();
    $mask = \Image::canvas($width, $height);

    // draw a white circle
    $mask->circle($width, $width/2, $height/2, function ($draw) {
        $draw->background('#fff');
    });

    $image->mask($mask, false);
    $image->save($path."circled.png");

}