RGBA格式HEX转换成RGB格式HEX? PHP [英] RGBA format HEX into RGB format HEX? PHP
问题描述
我想在RGBA格式HEX颜色(如 我怎样才能做到这一点? $在第一个实际上是混合背景色。 p> 编辑:修复由于没有足够的空间来损坏RGBA。 I want to convert back and forth between RGBA-formated HEX colors (like How can I do this? How about these: $blend in the first is effectively a background color to blend with. Edit: fix due to not enough space in ints ruining RGBA.
RGBA is now handled as a four part array. RGB remains a number.:
这篇关于RGBA格式HEX转换成RGB格式HEX? PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! 0xFF0000FF
)和RGB格式HEX颜色之间来回转换(如 0xFF0000 <
$ b
函数rgbaToRgb($ rgba,$ blend = 0xFFFFFF){
return (($ rgba>> 8)*($ rgba& 0xFF)/ 0xFF)*($ blend / 0xFFFFFF);
}
函数rgbToRgba($ rgb){
return($ rgb<< 8)| 0xFF的;
}
RGBA现在处理为四部分阵列。 RGB仍然是一个数字:
pre $ r $ b $ r $ ($ rgba [0] * $ rgba [3] / 0xFF +($ blend>> 16)*(0xFF- $ rgba [3])/ 0xFF,$ rgba [1] * $ rgba [3] / 0xFF + (0xFF- $ rgba [3])/ 0xFF,$ rgba [2] * $ rgba [3] / 0xFF +($ blend& 0xFF)*(0xFF- $ RGBA [3])/为0xFF);
return($ rbg [0] <= 16)+($ rbg [1] <8)+ $ rbg [2];
}
函数rgbToRgba($ rgb){
返回数组($ rgb>> 16,($ rgb>> 8)& 0xFF,$ rgb & 0xFF,0xFF);
}
0xFF0000FF
) and RGB-formated HEX colors (like 0xFF0000
) in PHP.function rgbaToRgb ($rgba, $blend = 0xFFFFFF) {
return (($rgba >> 8)*($rgba & 0xFF)/0xFF) * ($blend / 0xFFFFFF);
}
function rgbToRgba ($rgb) {
return ($rgb << 8) | 0xFF;
}
function rgbaToRgb ($rgba, $blend = 0xFFFFFF) {
$rbg = array($rgba[0] * $rgba[3]/0xFF + ($blend>>16) * (0xFF-$rgba[3])/0xFF, $rgba[1] * $rgba[3]/0xFF + (($blend>>8)&0xFF)*(0xFF-$rgba[3])/0xFF, $rgba[2] * $rgba[3]/0xFF + ($blend&0xFF) * (0xFF-$rgba[3])/0xFF);
return ($rbg[0]<<16) + ($rbg[1]<<8) + $rbg[2];
}
function rgbToRgba ($rgb) {
return array($rgb >> 16, ($rgb >> 8) & 0xFF, $rgb & 0xFF, 0xFF);
}