php laravel 图像介入中的Stream()函数是什么

php laravel What is the Stream() function in image intervention

请问图像介入中的stream()函数是做什么的? http://image.intervention.io/api/stream

现在我正在像这样将图像上传到亚马逊 S3:

public function uploadLargeAndMainImages($file,$adId)
  {
    $s3 = Storage::disk('s3');
    $extension = $file->guessExtension();
    $filename = uniqid() . '.' . $extension;

    //Create and resize images
    $image = Image::make($file)->resize(null, 600, function ($constraint) {
        $constraint->aspectRatio();
    });
    $image->encode($extension);

    $imageLarge = Image::make($file)->resize(null, 800, function ($constraint) {
        $constraint->aspectRatio();
    });
    $imageLarge->encode($extension);

    // upload image to S3
    $s3->put("images/{$adId}/main/" . $filename, (string) $image, 'public');
    $s3->put("images/{$adId}/large/" . $filename, (string) $imageLarge, 'public');

    // make image entry to DB
    $file = File::create([
        'a_f_id' => $adId,
        'file_name' => $filename,
    ]);

  }

都写在你上面提到的Intervention Docs:

The stream() method encodes the image in given format and given image quality and creates new PSR-7 stream based on image data.

它returns一个PSR-7 stream作为GuzzleHttp\Psr7\Stream的实例。

// encode png image as jpg stream
$stream = Image::make('public/foo.png')->stream('jpg', 60);

为了演示,您可以像这样对 S3 使用 stream() 方法:

...
$image_normal = Image::make($image)->widen(800, function ($constraint) {
    $constraint->upsize();
});
$image_thumb = Image::make($image)->crop(100,100);
$image_normal = $image_normal->stream();
$image_thumb = $image_thumb->stream();

Storage::disk('s3')->put($path.$file, $image_normal->__toString());
Storage::disk('s3')->put($path.'thumbnails/'.$file, $image_thumb->__toString());

它认为你明白了!