【问题标题】:Laravel Upload Image and Resize to Digital Ocean SpacesLaravel 上传图像并调整大小到数字海洋空间
【发布时间】:2020-02-05 03:07:38
【问题描述】:

我尝试上传图片并调整大小到数字海洋空间,但调整大小的图片代码不会调整大小

 $image = $request->file('image');

    /**
     * save resize image
     */

    $thumb_uploads = env('CLOUD_POSTS_IMAGE_THUMB');

    $image_resize = Image::make($image->getRealPath());

    $image_resize->resize(50, 50, function ($constraint) {

        $constraint->aspectRatio();

    })->save(Storage::disk('spaces')->put($thumb_uploads .'/'.$image->hashName(), file_get_contents($image), 'public'));

【问题讨论】:

    标签: laravel resize spaces digital ocean


    【解决方案1】:

    试试这个,你应该使用调整大小的图片内容。

    $image_resize = $image_resize->resize(50, 50, function ($constraint) {
        $constraint->aspectRatio();
    })->encode('jpg');
    
    Storage::disk('spaces')->put($thumb_uploads .'/'.$image->hashName(), (string) $image_resize);
    

    【讨论】:

    • 谢谢先生,图片已上传,但图片打不开
    • 在将图像放入磁盘时确保图像的可见性为public
    • 我尝试添加到公共,仍然相同``` Storage::disk('spaces')->put($thumb_uploads .'/'.$image->hashName(), $image_resize ->__toString(), 'public'); ``` 我试试 dd($image_resize->__toString()) 这个输出为空
    • 您究竟是如何获取图像的?
    • 我正在检查空间数字海洋
    猜你喜欢
    • 1970-01-01
    • 2016-03-02
    • 2020-07-11
    • 2021-04-25
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 2023-04-11
    • 2012-01-10
    相关资源
    最近更新 更多