Creating thumbs using Intervention\Image

Controller

use Intervention\Image\Facades\Image;

    public function make_thumbs(){
        $root = 'app/media/product';
        $thumb_root = 'app/thumbs/product';
        //logg(storage_path($root));
        $width = 122;
        $height = 91;

        $this->process_folder($root, $thumb_root, $width, $height);
        echo 'done';
    }

    private function process_folder($path, $thumb_root, $width, $height){
        $file_path = storage_path($path);
        $thumb_full_path = storage_path($thumb_root);
        if(file_exists($thumb_full_path) == false){
            mkdir($thumb_full_path, 0777);
        }

        $files = scandir($file_path);
        //logg($files);
        foreach ($files as $key => $file) {
            if($file == '.' || $file == '..'){
                continue;
            }

            if(is_dir($file_path . '/' . $file) == true){
                $this->process_folder(
                    $path . '/' . $file, 
                    $thumb_root . '/' . $file,
                    $width, 
                    $height
                );
            }else{
                if(file_exists($thumb_full_path . '/' . $file) == true){
                    continue;
                }

                $path_parts = pathinfo($file);
                if(isset($path_parts['extension'])){
                    $ext = strtolower($path_parts['extension']);
                    if(in_array($ext, ['jpg', 'png', 'gif']) == true){
                        $img = Image::make($file_path . '/' . $file)
                            ->fit($width, $height)
                            ->save($thumb_full_path . '/' . $file);
                    }
                }
            }
        }
    }

Using Storage

    public static function make_thumb($path){
        //$path = '/images/W3G2wXleWkKj9gJwbAdA60SNp5urp5emA2mulpAh.jpeg';
        $file_name = basename($path);
        $file_path = Storage::disk('public')->path($path);

        $thumb_dir = dirname($path) . '/thumbs';
        Storage::disk('public')->makeDirectory($thumb_dir);
        $thumb_path = Storage::disk('public')->path($thumb_dir . '/' . $file_name);

        $img = Image::make($file_path)
            ->fit(300, 150)
            ->save($thumb_path);
    }

    public static function get_thumb($path){
        $thumb_dir = dirname($path) . '/thumbs';
        $file_name = basename($path);
        $url = Storage::disk('public')->url($thumb_dir . '/' . $file_name);
        return $url;
    }

Control ratio

    private function make_thumb($file){
        $file_path = storage_path('/app/media' . $file);
        //logg(file_exists($file_path));
        //logg($file_path);

        $img = Image::make($file_path);
        $img->resize(600, null, function ($constraint) {
            $constraint->aspectRatio();
        });

        $dir_name = CategoryM::PRODUCT_CAT_THUMB_DIR;
        $thumb_dir = storage_path('/app/' . $dir_name . dirname($file));
        if(file_exists($thumb_dir) == false){
            File::makeDirectory($thumb_dir, 0777, true, true);
        }

        $thumb = storage_path('/app/' . $dir_name . $file);
        $img->save($thumb);
    }