It seems you just forgot the Delimiter
preg_match("~/$~", $this->library_path)
and
preg_match("~gd2$~i", $protocol)
But in both cases you should consider not using regular expressions, because they are oversized here
$this->library_path[strlen($this->library_path) - 1] == '/'
substr($protocol, -3) == 'gd2'