在Codeigniter中加载库时出现PHP错误

I've included the ColorsOfImage PHP class from humanmade into my Codeigniter as a new library.

Now when I load the library in a controller, I can use the functions of the class without any problems, but I always get the following error when loading the library, which says, that the $image in the __construct function is empty!?

Here is the __construct function of the class:

public function __construct( $image, $precision = 10, $maxnumcolors = 5, $trueper = true ) {
        $this->image = $image;
        $this->maxnumcolors = $maxnumcolors;
        $this->trueper = $trueper;
        $this->getImageSize();
        $this->precision = $precision;
        $this->readPixels();
        $this->_excluded_colors[] = $this->getBackgroundColor();
    }

You should check docs where is said:

library($library[, $params = NULL[, $object_name = NULL]])

Parameters:

  • $library (mixed) – Library name as a string or an array with multiple libraries
  • $params (array) – Optional array of parameters to pass to the loaded library’s constructor
  • $object_name (string) – Optional object name to assign the library to

In case of CI using custom library with constructor parameters from a controller:

$this->load->library('colorsofimage', [$image, $precision = 10, $maxnumcolors = 5, $trueper = true]);