2015-10-23

[PHP] 從 Hex 轉換到 RGB

function hex2rgb($hex) {
    list($r, $g, $b) = sscanf($hex, "%02x%02x%02x");
    return array('red' => $r, 'green' => $g, 'blue' => $b);
}

function rgb2hex($rgb) {
    return sprintf("%02x%02x%02x", $rgb['red'], $rgb['green'], $rgb['blue']);
}

0 回應: