函数文档

wp_tinycolor_hue_to_rgb()

💡 云策文档标注

概述

wp_tinycolor_hue_to_rgb() 是一个用于将 HSL 颜色值转换为 RGB 的辅助函数,基于 TinyColor 库实现,但已从 WordPress 6.3.0 版本起被弃用。

关键要点

  • 这是一个辅助函数,用于 HSL 到 RGB 颜色转换中的色调分量计算。
  • 函数是 TinyColor 库的直接移植版本,经过简化以保持一致性。
  • 从 WordPress 6.3.0 版本开始被弃用,建议使用替代方法。
  • 接受三个浮点参数 $p、$q、$t,返回一个浮点值,代表 R、G 或 B 分量。
  • 相关函数包括 wp_tinycolor_hsl_to_rgb(),它使用此函数进行转换。

代码示例

function wp_tinycolor_hue_to_rgb( $p, $q, $t ) {
    _deprecated_function( __FUNCTION__, '6.3.0' );

    if ( $t < 0 ) {
        ++$t;
    }
    if ( $t > 1 ) {
        --$t;
    }
    if ( $t < 1/6 ) {
        return $p + ( $q - $p ) * 6 * $t;
    }
    if ( $t < 1/2 ) {
        return $q;
    }
    if ( $t < 2/3 ) {
        return $p + ( $q - $p ) * ( 2/3 - $t ) * 6;
    }
    return $p;
}

注意事项

此函数已被弃用,开发者应避免在新代码中使用,并考虑迁移到其他颜色转换方法。


📄 原文内容

Helper function for hsl to rgb conversion.

Description

Direct port of TinyColor’s function, lightly simplified to maintain consistency with TinyColor.

Parameters

$pfloatrequired
first component.
$qfloatrequired
second component.
$tfloatrequired
third component.

Return

float R, G, or B component.

Source

function wp_tinycolor_hue_to_rgb( $p, $q, $t ) {
	_deprecated_function( __FUNCTION__, '6.3.0' );

	if ( $t < 0 ) {
		++$t;
	}
	if ( $t > 1 ) {
		--$t;
	}
	if ( $t < 1 / 6 ) {
		return $p + ( $q - $p ) * 6 * $t;
	}
	if ( $t < 1 / 2 ) {
		return $q;
	}
	if ( $t < 2 / 3 ) {
		return $p + ( $q - $p ) * ( 2 / 3 - $t ) * 6;
	}
	return $p;
}

Changelog

Version Description
6.3.0 Deprecated.
5.8.0 Introduced.