protected function registerDriver()
    {
        $app = $this->app;

        $config  = $app['config'];

        $storage = $config->get('jitimage::cache.path');

        $driver = sprintf(
            '\Thapp\JitImage\Driver\%sDriver',
            $driverName = ucfirst($config->get('jitimage::driver', 'gd'))
        );

        $app->bind(
            'Thapp\JitImage\Cache\CacheInterface',
            function () use ($storage) {
                $cache = new \Thapp\JitImage\Cache\ImageCache(
                    new CachedImage,
                    //$this->app['Thapp\JitImage\ImageInterface'],
                    new Filesystem,
                    $storage . '/jit'
                );
                return $cache;
            }
        );


        $app->bind('Thapp\JitImage\Driver\SourceLoaderInterface', 'Thapp\JitImage\Driver\ImageSourceLoader');

        $app->bind('Thapp\JitImage\Driver\BinLocatorInterface', function () use ($config) {
            $locator = new \Thapp\JitImage\Driver\ImBinLocator;
            extract($config->get('jitimage::imagemagick', ['path' => '/usr/local/bin', 'bin' => 'convert']));

            $locator->setConverterPath(
                sprintf('%s%s%s', rtrim($path, DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR, $bin)
            );

            return $locator;
        });


        $this->app->bind('Thapp\JitImage\Driver\DriverInterface', function () use ($driver) {
            return $this->app->make($driver);
        });
        
        $this->app->bind('Thapp\JitImage\ImageInterface', function () use ($app) {
            return new ProxyImage(function () use ($app) {
                $image = new Image($app->make('Thapp\JitImage\Driver\DriverInterface'));
                $image->setQuality($app['config']->get('jitimage::quality', 80));
                return $image;
            });
        });

        //$this->app->extend(
        //    'Thapp\JitImage\ImageInterface',
        //    function ($image) {
        //        $image->setQuality($this->app['config']->get('jitimage::quality', 80));
        //        return $image;
        //    }
        //);

        $this->app['jitimage'] = $this->app->share(
            function () use ($app) {
                $resolver = $app->make('Thapp\JitImage\ResolverInterface');
                $image = new JitImage($resolver, \URL::to('/'));
                return $image;
            }
        );

        $this->app['jitimage.cache'] = $this->app->share(
            function () {
                return $this->app->make('Thapp\JitImage\Cache\CacheInterface');
            }
        );

        $this->registerFilter($driverName, $this->getFilters());
    }