File: C:/xampp/htdocs/FograCT1/FWspotreportapiLab.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Control-9 Check</title>
<style type="text/css">
body,td,th {
font-size: 12px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
.ssss {
font-size: 12px;
color: #F00;
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
border-top-style: 0;
border-right-style: 0;
border-bottom-style: 0;
border-left-style: 0;
}
.z {
color: #CCC;
}
.SS {
color: #F00;
}
body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background: #ffffff;
margin: 0; /* 比較好的做法是將 Body 元素的邊界與欄位間隔調整為零,以處理不同的瀏覽器預設值 */
padding: 0;
text-align: center; /* 這樣會讓容器在 IE 5* 瀏覽器內置中對齊。然後,文字會在 #container 選取器中設定為靠左對齊預設值 */
color: #000000;
}
.oneColElsCtr #container {
width: 46em;
background: #FFFFFF;
margin: 0 auto; /* 自動邊界 (搭配寬度) 會讓頁面置中對齊 */
border: 0px solid #000000;
text-align: left; /* 這樣做會覆寫 Body 元素上的 text-align: center。 */
}
.oneColElsCtr #mainContent {
padding: 0 20px; /* 請記住,欄位間隔就是 Div 方塊內部的空間,而邊界就是 Div 方塊外部的空間 */
}aph
</style></head>
<body class="oneColElsCtr">
<body class="oneColElsCtr">
<head><h1> 特別色 分析報告</h1> </head>
<?php
//error_reporting(0);
$f123= $_GET['f123'];
$f321= $_GET['f321'];
$color1= $_GET['color1'];
$po= $_GET['po'];
$company= $_GET['company'];
$overwrite= $_GET['overwrite'];
if ($overwrite==''){
$overwrite=0;
}
$double= $_GET['double'];
if ($double==''){
$double=0;
}
echo "ovx & double:".$overwrite.",".$double;
$filename=substr($f321,7,60);
include 'sp38XYZ.php';
include 'lab2xyz.php';
include 'xyz2lab01.php';
include 'xyz2lab.php';
include 'de00.php';
include 'DensityV38.php';
$contentT = file($f321);
$stringT = implode($contentT);
//echo $contents[20];
//echo $stringT;
$pp = str_replace("\r\n", " ", $stringT);
//$pp = str_replace("\r\n", " ", $pp);
$dotTx = explode("_", $pp);////Measure upload
//print_r ($dotTx);
foreach ($dotTx as $value) {
$dotT[] = $value * 1;
}
//print_r ($dotT);
$S0Lm=round($dotT[3],2);
$S0am=round($dotT[4],2);
$S0bm=round($dotT[5],2);
$S1Lm=round($dotT[0],2);
$S1am=round($dotT[1],2);
$S1bm=round($dotT[2],2);
$S2Lm=round($dotT[6],2);
$S2am=round($dotT[7],2);
$S2bm=round($dotT[8],2);
$stdSum=0;
////////////////////////Lab to RGB
function labToD50sRGB($L, $a, $b) {
// D50 reference white
$Xn = 96.422*0.01; // X
$Yn = 100.0*0.01; // Y
$Zn = 82.521*0.01; // Z
// Lab to XYZ
$Y = ($L + 16) / 116;
$X = $a / 500 + $Y;
$Z = $Y - $b / 200;
// Reverse the f(t) function
$X = $Xn * (($X ** 3 > 0.008856) ? ($X ** 3) : ((116 * $X - 16) / 903.3));
$Y = $Yn * (($Y ** 3 > 0.008856) ? ($Y ** 3) : ((116 * $Y - 16) / 903.3));
$Z = $Zn * (($Z ** 3 > 0.008856) ? ($Z ** 3) : ((116 * $Z - 16) / 903.3));
// Convert XYZ (D50) to linear sRGB (D50 matrix)
$R = 3.1338561 * $X - 1.6168667 * $Y - 0.4906146 * $Z;
$G = -0.9787684 * $X + 1.9161415 * $Y + 0.0334540 * $Z;
$B = 0.0719453 * $X - 0.2289914 * $Y + 1.4052427 * $Z;
// Linear sRGB to sRGB (gamma correction)
$R = $R <= 0.0031308 ? 12.92 * $R : (1.055 * ($R ** (1 / 2.4)) - 0.055);
$G = $G <= 0.0031308 ? 12.92 * $G : (1.055 * ($G ** (1 / 2.4)) - 0.055);
$B = $B <= 0.0031308 ? 12.92 * $B : (1.055 * ($B ** (1 / 2.4)) - 0.055);
// Clamp and scale to 0-255 range
$R = max(0, min(255, round($R * 255)));
$G = max(0, min(255, round($G * 255)));
$B = max(0, min(255, round($B * 255)));
return [$R, $G, $B];
}
// Example usage
//$lab = [68.71, 8.05, 24.89];
list($R, $G, $B) = labToD50sRGB(68.71, 8.05, 24.89);
echo "sRGB: [$R, $G, $B]";
///////////////////////////////
function RGBToHex($r, $g, $b) {
//String padding bug found and the solution put forth by Pete Williams (http://snipplr.com/users/PeteW)
$hex = "#";
$hex.= str_pad(dechex($r), 2, "0", STR_PAD_LEFT);
$hex.= str_pad(dechex($g), 2, "0", STR_PAD_LEFT);
$hex.= str_pad(dechex($b), 2, "0", STR_PAD_LEFT);
return $hex;
}
// Example usage
//$cieXYZ = [$S0Xm, $S0Ym, $S0Zm]; // Example CIE XYZ values
$sRGB = labToD50sRGB($S0Lm, $S0am, $S0bm);
echo "sRGB: R={$sRGB[0]}, G={$sRGB[1]}, B={$sRGB[2]}";
$sR = $sRGB[0];
$sG = $sRGB[1];
$sB = $sRGB[2];
$ch1C4=RGBToHex($sR,$sG,$sB);
$ch1C4s=substr($ch1C4,1);
echo "<br>_hex 252:".$ch1C4;
//$cieXYZ = [$S1Xm, $S1Ym, $S1Zm]; // Example CIE XYZ values
$sRGB = labToD50sRGB($S1Lm, $S1am, $S1bm);
echo "sRGB2: R={$sRGB[0]}, G={$sRGB[1]}, B={$sRGB[2]}";
$sR = $sRGB[0];
$sG = $sRGB[1];
$sB = $sRGB[2];
$ch1C3=RGBToHex($sR,$sG,$sB);
$ch1C3s=substr($ch1C3,1);
echo "_hex 261:".$ch1C3;
echo "_hex 262:".$ch1C3s;
//$cieXYZ = [$S2Xm, $S2Ym, $S2Zm]; // Example CIE XYZ values
$sRGB = labToD50sRGB($S2Lm, $S2am, $S2bm);
//echo "sRGB: R={$sRGB[0]}, G={$sRGB[1]}, B={$sRGB[2]}";
$sR = $sRGB[0];
$sG = $sRGB[1];
$sB = $sRGB[2];
$ch1C5=RGBToHex($sR,$sG,$sB);
$ch1C5s=substr($ch1C5,1);
echo "_hex 270:".$ch1C5;
//echo "_hex:".$ch1C5;
$deUp=round(de00($S0Lm,$S0am,$S0bm,$S1Lm,$S1am,$S1bm),2);
$deLo=round(de00($S1Lm,$S1am,$S1bm,$S2Lm,$S2am,$S2bm),2);
?>
<table width="600" align="center">
<tr>
<td>印號:<?php echo $po?></td>
</tr>
</table>
<table width="600" border="1" align="center">
<tr>
<td><?php echo $color1?></td>
<td bgcolor="<?php echo $ch1C4;?>">上限</td><td bgcolor="<?php echo $ch1C3;?>">標準</td><td bgcolor="<?php echo $ch1C5;?>">下限</td>
</tr>
<tr>
<td>L</td>
<td><?php echo $S0Lm;?></td><td><?php echo $S1Lm;?></td><td><?php echo $S2Lm;?></td>
</tr>
<tr>
<td>a</td>
<td><?php echo $S0am;?></td><td><?php echo $S1am;?></td><td><?php echo $S2am;?></td>
</tr>
<tr>
<td>b</td>
<td><?php echo $S0bm;?></td><td><?php echo $S1bm;?></td><td><?php echo $S2bm;?></td>
</tr>
<tr>
<td>ΔE00</td>
<td><?php echo $deUp;?></td><td></td><td><?php echo $deLo;?></td>
</tr>
<tr>
</tr>
</table>
<?php
// Build the URL with parameters
$fullUrl = 'https://quickchart.io/qr?text='.$company.','.$po.'&size=256';
// Output the QR code image
echo "<img src='" . $fullUrl . "' alt='QR Code'>";
?>
<?php
$sn="na";
$servername = "127.0.0.1";
$username = "root";
$password = "fredsql";
$DBNAME = "tvicheck-st";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//echo "Connected successfully";
if( !mysqli_select_db($conn, $DBNAME)) {
die ("無法選擇資料庫");
}
mysqli_query( $conn, "SET NAMES 'utf8'");
$querys = "select po from spotreport where (po='$po'and company='$company') ORDER BY id DESC LIMIT 1 ";
//echo $querys."<br>";
$results = mysqli_query($conn, $querys);
$num = mysqli_num_rows( $results);
if ($num > 0 and $overwrite==0)
{
//$row = mysqli_fetch_object($results);
//$CTcount=$row->CTcount;
echo "double job code";
if ($double==0){
header("Location: http://fredkuo.idv.tw/FograCT1/FWspotTransLab.php?f123=target.txt&f321=".$f321."&po=".$po."&company=".$company);
exit(); // Ensure that following code is not executed after redirection
}
}
elseif ($overwrite==0) {
$query = "INSERT INTO spotreport (po, sn,company,ddate, stdL,stda, stdb, rgbS, Filename, upL, upa, upb, rgbUp,LoL, Loa, Lob,rgbLo ) VALUES( '$po','$sn','$company',NOW(),'$S1Lm', '$S1am','$S1bm', '$ch1C3s','$filename','$S0Lm', '$S0am','$S0bm','$ch1C4s','$S2Lm', '$S2am','$S2bm','$ch1C5s')";
//echo $query;
//$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
$results = mysqli_query($conn, $query);
echo "data inserted!";
}
elseif ($overwrite==1) {
$query = "update spotreport set po='$po', sn='$sn',company='$company',ddate=NOW(), stdL='$S1Lm',stda='$S1am', stdb='$S1bm', rgbS='$ch1C3s', Filename='$filename', upL='$S0Lm', upa='$S0am', upb='$S0bm', rgbUp='$ch1C4s',LoL='$S2Lm', Loa='$S2am', Lob='$S2bm',rgbLo='$ch1C5s' where (po='$po' and company='$company') ";
//echo $query;
//$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
$results = mysqli_query($conn, $query);
echo "update data!";
}
mysqli_close($conn);
?>
<!--
<table align="center">
<tr>
<td align="center"><font size="-2"> © <a href="mailto:[email protected]">Fred Kuo</a>, 2023. All rights reserved.<br>
</td>
</tr>
</table>
-->
</body>
</html>