Create colortool.php

This commit is contained in:
Namhyeon Go 2019-07-14 19:48:09 +09:00 committed by GitHub
parent 8ba364bd4d
commit 45c3413d7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

65
helper/colortool.php Normal file
View File

@ -0,0 +1,65 @@
<?php
// colortool.php
if(!function_exists("color_lab_to_xyz")) {
function color_lab_to_xyz($l, $a, $b) {
$ref_X = 95.047;
$ref_Y = 100.000;
$ref_Z = 108.883;
$var_Y = ($this->lightness + 16) / 116;
$var_X = $this->a_dimension / 500 + $var_Y;
$var_Z = $var_Y - $this->b_dimension / 200;
if (pow($var_Y, 3) > 0.008856) {
$var_Y = pow($var_Y, 3);
} else {
$var_Y = ($var_Y - 16 / 116) / 7.787;
}
if (pow($var_X, 3) > 0.008856) {
$var_X = pow($var_X, 3);
} else {
$var_X = ($var_X - 16 / 116) / 7.787;
}
if (pow($var_Z, 3) > 0.008856) {
$var_Z = pow($var_Z, 3);
} else {
$var_Z = ($var_Z - 16 / 116) / 7.787;
}
$position_x = $ref_X * $var_X;
$position_y = $ref_Y * $var_Y;
$position_z = $ref_Z * $var_Z;
return array($position_x, $position_y, $position_z);
}
}
if(!function_exists("color_xyz_to_rgb")) {
function color_xyz_to_rgb($x, $y, $z) {
$var_X = $x / 100;
$var_Y = $y / 100;
$var_Z = $z / 100;
$var_R = $var_X * 3.2406 + $var_Y * -1.5372 + $var_Z * -0.4986;
$var_G = $var_X * -0.9689 + $var_Y * 1.8758 + $var_Z * 0.0415;
$var_B = $var_X * 0.0557 + $var_Y * -0.2040 + $var_Z * 1.0570;
if ($var_R > 0.0031308) {
$var_R = 1.055 * pow($var_R, (1 / 2.4)) - 0.055;
} else {
$var_R = 12.92 * $var_R;
}
if ($var_G > 0.0031308) {
$var_G = 1.055 * pow($var_G, (1 / 2.4)) - 0.055;
} else {
$var_G = 12.92 * $var_G;
}
if ($var_B > 0.0031308) {
$var_B = 1.055 * pow($var_B, (1 / 2.4)) - 0.055;
} else {
$var_B = 12.92 * $var_B;
}
$var_R = max(0, min(255, $var_R * 255));
$var_G = max(0, min(255, $var_G * 255));
$var_B = max(0, min(255, $var_B * 255));
return array($var_R, $var_G, $var_B);
}
}