Finally i made my own function:
The input is the result of getColorAsString methon from ImagickPixel. I cannot make this directly because the output of the method is in a 3rd party library
function iMagickColorToHEX($string)
{
$pixel = new ImagickPixel($string);
$color = $pixel->getColor();
return sprintf('#%s%s%s',
dechex($color['r']),
dechex($color['g']),
dechex($color['b'])
);
}