Search code examples
laravelresizespacesdigitalocean

Laravel Upload Image and Resize to Digital Ocean Spaces


I try upload image and resize to digital ocean spaces, but the resize image code doesn't resize

 $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'));

Solution

  • Try this, you should use the resized images content.

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