Phalcon\Image\Adapter\GD not work on Dependency Injector

I try to call Phalcon\Image\Adapter\GD from Dependency Injector, but it not working

$di->set('image', function() { // create an image manager instance with favored driver $image = new Phalcon\Image\Adapter\GD(); return $image; });

calling DI

$this->image('path/image.jpg')->resize(200,200)->save();

get error



64.2k
edited Nov '15

ah it didnt matter shared or not

https://docs.phalconphp.com/en/latest/reference/di.html#shared-services

$di->set('name', function(){}, TRUE);

Dear lzo,

$di->setShared('name', function(){}); $di->set('name', function(){}, TRUE);

still not working



966
edited Nov '15

Please try

$di->set('image', [
    'className' => 'Phalcon\Image\Adapter\GD',
    'arguments' => [
        [
            'type'  => 'parameter',
            'value' => 'path/image.jpg' // default parameter may be a null I think
        ]
    ]
]);

Calling DI

$di->getService('image')->setParameter(0, array(
    'type'  => 'parameter',
    'value' => 'path/image.jpg'
))->resize(200,200)->save();

https://docs.phalconphp.com/en/latest/reference/di.html#complex-registration