public function loadPalette($FileName, $Overwrite = false)
    {
        $path = file_exists($FileName)
            ? $FileName
            : sprintf('%s/../resources/palettes/%s', __DIR__, ltrim($FileName, '/'))
        ;

        $fileHandle = @fopen($path, "r");
        if (!$fileHandle) {
            throw new Exception(sprintf(
                'The requested palette "%s" was not found at path "%s"!',
                $FileName,
                $path
            ));
        }

        if ($Overwrite) {
            $this->Palette = [];
        }

        while (!feof($fileHandle)) {
            $line = fgets($fileHandle, 4096);
            if (false === $line) {
                continue;
            }
            $row = explode(',', $line);
            if (empty($row)) {
                continue;
            }
            if (count($row) !== 4) {
                throw new RuntimeException(sprintf(
                    'A palette row must supply R, G, B and Alpha components, %s given!',
                    var_export($row, true)
                ));
            }
            list($R, $G, $B, $Alpha) = $row;
            $ID = count($this->Palette);
            $this->Palette[$ID] = [
                "R" => trim($R),
                "G" => trim($G),
                "B" => trim($B),
                "Alpha" => trim($Alpha)
            ];
        }
        fclose($fileHandle);

        /* Apply changes to current series */
        $ID = 0;
        if (isset($this->Data["Series"])) {
            foreach ($this->Data["Series"] as $Key => $Value) {
                if (!isset($this->Palette[$ID])) {
                    $this->Data["Series"][$Key]["Color"] = ["R" => 0, "G" => 0, "B" => 0, "Alpha" => 0];
                } else {
                    $this->Data["Series"][$Key]["Color"] = $this->Palette[$ID];
                }
                $ID++;
            }
        }
    }
public function loadPalette($FileName, $Overwrite = false)
    {
        $path = file_exists($FileName)
            ? $FileName
            : sprintf('%s/../resources/palettes/%s', __DIR__, ltrim($FileName, '/'))
        ;

        $fileHandle = @fopen($path, "r");
        if (!$fileHandle) {
            throw new Exception(sprintf(
                'The requested palette "%s" was not found at path "%s"!',
                $FileName,
                $path
            ));
        }

        if ($Overwrite) {
            $this->Palette = [];
        }

        while (!feof($fileHandle)) {
            $line = fgets($fileHandle, 4096);
            if (false === $line) {
                continue;
            }
            $row = explode(',', $line);
            if (empty($row)) {
                continue;
            }
            if (count($row) !== 4) {
                throw new RuntimeException(sprintf(
                    'A palette row must supply R, G, B and Alpha components, %s given!',
                    var_export($row, true)
                ));
            }
            list($R, $G, $B, $Alpha) = $row;
            $ID = count($this->Palette);
            $this->Palette[$ID] = [
                "R" => trim($R),
                "G" => trim($G),
                "B" => trim($B),
                "Alpha" => trim($Alpha)
            ];
        }
        fclose($fileHandle);

        /* Apply changes to current series */
        $ID = 0;
        if (isset($this->Data["Series"])) {
            foreach ($this->Data["Series"] as $Key => $Value) {
                if (!isset($this->Palette[$ID])) {
                    $this->Data["Series"][$Key]["Color"] = ["R" => 0, "G" => 0, "B" => 0, "Alpha" => 0];
                } else {
                    $this->Data["Series"][$Key]["Color"] = $this->Palette[$ID];
                }
                $ID++;
            }
        }
    }
public function loadPalette ( $ FileName , $ Overwrite = false ) { $ path = file_exists ( $ FileName ) ? $ FileName : sprintf ( '%s/../resources/palettes/%s' , __DIR__ , ltrim ( $ FileName , '/' ) ) ; $ fileHandle = @ fopen ( $ path , "r" ) ; if ( ! $ fileHandle ) { throw new Exception ( sprintf ( 'The requested palette "%s" was not found at path "%s"!' , $ FileName , $ path ) ) ; } if ( $ Overwrite ) { $ this -> Palette = [ ] ; } while ( ! feof ( $ fileHandle ) ) { $ line = fgets ( $ fileHandle , 4096 ) ; if ( false === $ line ) { continue ; } $ row = explode ( ',' , $ line ) ; if ( empty ( $ row ) ) { continue ; } if ( count ( $ row ) !== 4 ) { throw new RuntimeException ( sprintf ( 'A palette row must supply R, G, B and Alpha components, %s given!' , var_export ( $ row , true ) ) ) ; } list ( $ R , $ G , $ B , $ Alpha ) = $ row ; $ ID = count ( $ this -> Palette ) ; $ this -> Palette [ $ ID ] = [ "R" => trim ( $ R ) , "G" => trim ( $ G ) , "B" => trim ( $ B ) , "Alpha" => trim ( $ Alpha ) ] ; } fclose ( $ fileHandle ) ; /* Apply changes to current series */ $ ID = 0 ; if ( isset ( $ this -> Data [ "Series" ] ) ) { foreach ( $ this -> Data [ "Series" ] as $ Key => $ Value ) { if ( ! isset ( $ this -> Palette [ $ ID ] ) ) { $ this -> Data [ "Series" ] [ $ Key ] [ "Color" ] = [ "R" => 0 , "G" => 0 , "B" => 0 , "Alpha" => 0 ] ; } else { $ this -> Data [ "Series" ] [ $ Key ] [ "Color" ] = $ this -> Palette [ $ ID ] ; } $ ID ++ ; } } }
Load a palette file
@param string $FileName
@param boolean $Overwrite
@throws Exception
Load a palette file