We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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



85.5k
edited Nov '15

ah it didnt matter shared or not

https://docs.phalcon.io/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



2.0k
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.phalcon.io/en/latest/reference/di.html#complex-registration