문제

I am working with imagick extension from PHP, and i want get to the HEX Code from a ImagickPixel object, if i use getColorAsString the result is a srgb format color.

echo $pixel->getColorAsString();
//return srgb(62.128633554589150378%,78.681620508125433844%,74.308384832532240694%)

Any built-in function or a custom one, for cast this format to HEX Code?

도움이 되었습니까?

해결책

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'])
    );
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top