【问题标题】:laravel livewire intervention imageslaravel livewire 干预 图片
【发布时间】:2021-03-15 23:56:27
【问题描述】:

我正在尝试使用带有 Livewire 的干预图像来减小尺寸,但我没有成功。如果 Livewire 不允许,他们可以指导我或告诉我。

我正在尝试通过这种方法:

foreach ($this->imagenes as $pathGaleria) {
             $imgUrl = $pathGaleria->store('imagenesPropiedades');

             $img = imgPropiedades::create([
               'url' => $imgUrl,
               'property_id' => $this->propiedadId
             ]);

换一种方式:

foreach ($this->imagenes as $pathGaleria) {
            $imgUrl = $pathGaleria->store('imagenesPropiedades');
            Image::make($pathGaleria)->resize(1200, null, function ($constraint) {
                $constraint->aspectRatio();
            })
            ->save($imgUrl);
            $img = imgPropiedades::create([
                'url' => $imgUrl,
                'property_id' => $this->propiedadId
            ]);

        }

但页面仍然空白。谢谢。

【问题讨论】:

    标签: laravel file-upload laravel-7 laravel-livewire


    【解决方案1】:

    我今天找到了这个,可能对你有用

    https://gist.github.com/daugaard47/659984245d31b895d00ee5dcbdee44ec

    +

    $images = Collection::wrap($request->file('file'));

        $images->each(function ($image) use ($id) {
            $basename = Str::random();
            $original = $basename . '.' . $image->getClientOriginalExtension();
            $thumbnail = $basename . '_thumb.' . $image->getClientOriginalExtension();
    
            ImageManager::make($image)
                ->fit(250, 250)
                ->save(public_path('/images/' . $thumbnail));
    
            $image->move(public_path('/images/'), $original);
    
            Model::create([
              
            ]);
        });
    

    【讨论】:

      猜你喜欢
      • 2018-01-06
      • 1970-01-01
      • 1970-01-01
      • 2015-06-01
      • 2015-02-09
      • 1970-01-01
      • 2014-12-06
      • 1970-01-01
      • 2020-12-17
      相关资源
      最近更新 更多