我正在尝试在 PHP 中应用 css hue-rotate 过滤器结果
目前我正在使用 Imagick
php 库,使用 modulateImage 函数来像这样改变色调
function modulateImage($imagePath, $hue, $brightness, $saturation) {
$imagick = new \Imagick(realpath($imagePath));
$imagick->modulateImage($brightness, $saturation, $hue);
header("Content-Type: image/jpg");
echo $imagick->getImageBlob();
}
但出于某种原因,将 CSS 的 hue-rotate
的相同值应用于 PHP 函数会给我不同的颜色结果,我不确定它们两者中使用的计算/百分比/度数,我希望有人可以解释或为他们提供任何替代方案(主要是 PHP 的替代方案,我发现 CSS 过滤器非常适合我的需求,我只需要在 PHP 中应用相同的方法)
最佳答案
imagick 中的 modulateImage 需要 $hue 的百分比,而 css 需要度数。这是要转换的公式:http://www.imagemagick.org/Usage/color_mods/#modulate_hue
hue_angle = ( modulate_arg - 100 ) * 180/100;
modulate_arg = ( hue_angle * 100/180 ) + 100;
关于php - CSS `hue-rotate` 过滤器到 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29984288/