<div id="container">
<?php
/*
*****************************************************
* convertitore di valori colori *
* percento di colore rosso, verde, blu (da 0 a 100) *
* valore decimale RGB (da 0 a 255) *
* valore esadecimae HTML (da 0 a ff) *
* valori RAL (approssimati) *
*****************************************************
* realizzazione gianni *
* www.borgo-italia.it *
* info[at]borgo-italia.it *
*---------------------------------------------------*
* se lo usate e trovate degli errori informatemi *
*****************************************************
*/
//*array colori RAL**da RAL 1000 a RAL 9018*******************************************
//si possono aggiungere anche altri valori !!!commentare questo e decommentare successiva o viceversa
/*
$ral=array("RAL_1000"=>"ccc188","RAL_1001"=>"ceb487","RAL_1002"=>"d0b173","RAL_1003"=>"f2ad00","RAL_1004"=>"e4a700","RAL_1005"=>"c79600","RAL_1006"=>"d99300","RAL_1007"=>"e69400","RAL_1011"=>"d8ba2e","RAL_1012"=>"af8552","RAL_1013"=>"e5dfcc","RAL_1014"=>"dfcea1","RAL_1015"=>"e6d9bd","RAL_1016"=>"ecea41","RAL_1017"=>"f6b256","RAL_1018"=>"fdda38","RAL_1019"=>"a6937b","RAL_1020"=>"a09465","RAL_1021"=>"f2c000","RAL_1023"=>"f2bf00","RAL_1024"=>"b89650","RAL_1027"=>"a4861a","RAL_1028"=>"ffa600","RAL_1032"=>"e2ac00","RAL_1033"=>"f7a11f","RAL_1034"=>"eba557","RAL_2000"=>"d97604","RAL_2001"=>"bb4926","RAL_2002"=>"c13524","RAL_2003"=>"f97a31","RAL_2004"=>"e8540d","RAL_2008"=>"f46f29","RAL_2009"=>"db5316","RAL_2010"=>"d55d23","RAL_2011"=>"ea7625","RAL_2012"=>"d6654e","RAL_3000"=>"a02725","RAL_3001"=>"a0001c","RAL_3002"=>"991424","RAL_3003"=>"870a24","RAL_3004"=>"6c1b2a","RAL_3005"=>"581e29","RAL_3007"=>"402226","RAL_3009"=>"6d312b","RAL_3011"=>"791f24","RAL_3012"=>"c68873","RAL_3013"=>"992a28","RAL_3014"=>"cf7278","RAL_3015"=>"e3a0ac","RAL_3016"=>"ab392d","RAL_3017"=>"cc515e","RAL_3018"=>"ca3f51","RAL_3020"=>"bf111b","RAL_3022"=>"d36b56","RAL_3027"=>"b01d42","RAL_3031"=>"a7323e","RAL_4001"=>"865d86","RAL_4002"=>"8f3f51","RAL_4003"=>"ca5b91","RAL_4004"=>"69193b","RAL_4005"=>"7e63a1","RAL_4006"=>"912d76","RAL_4007"=>"48233e","RAL_4008"=>"853d7d","RAL_4009"=>"9d8493","RAL_5000"=>"2f4a71","RAL_5001"=>"0e4666","RAL_5002"=>"162e7b","RAL_5003"=>"193058","RAL_5004"=>"1a1d2a","RAL_5005"=>"004389","RAL_5007"=>"38618c","RAL_5008"=>"2d3944 ","RAL_5009"=>"245878","RAL_5010"=>"00427f","RAL_5011"=>"1a2740","RAL_5012"=>"2781bb","RAL_5013"=>"202e53","RAL_5014"=>"667b9a","RAL_5015"=>"0071b5","RAL_5017"=>"004c91","RAL_5018"=>"138992","RAL_5019"=>"005688","RAL_5020"=>"00747d","RAL_5021"=>"00747d","RAL_5022"=>"28275a","RAL_5023"=>"486591","RAL_5024"=>"6391b0","RAL_6000"=>"327663","RAL_6001"=>"266d3b","RAL_6002"=>"276230","RAL_6003"=>"4e553d","RAL_6004"=>"004547","RAL_6005"=>"0e4438","RAL_6006"=>"3b3d33","RAL_6007"=>"2b3626","RAL_6008"=>"302f22","RAL_6009"=>"213529","RAL_6010"=>"426e38","RAL_6011"=>"68825f","RAL_6012"=>"293a37","RAL_6013"=>"76785b","RAL_6014"=>"443f31","RAL_6015"=>"383b34","RAL_6016"=>"00664f","RAL_6017"=>"4d8542","RAL_6018"=>"4b9b3e","RAL_6019"=>"b2d8b4","RAL_6020"=>"394937","RAL_6021"=>"87a180","RAL_6022"=>"3c372a","RAL_6024"=>"008455","RAL_6025"=>"56723d","RAL_6026"=>"005c54","RAL_6027"=>"77bbbd","RAL_6028"=>"2e554b","RAL_6029"=>"006f43","RAL_6032"=>"00855a","RAL_6033"=>"3f8884","RAL_6034"=>"75adb1","RAL_7000"=>"798790","RAL_7001"=>"8c969f","RAL_7001"=>"8c969f","RAL_7002"=>"827d67","RAL_7003"=>"79796c","RAL_7004"=>"999a9f","RAL_7005"=>"999a9f","RAL_7006"=>"766a5d","RAL_7008"=>"756444","RAL_7009"=>"585e55","RAL_7010"=>"565957","RAL_7011"=>"525a60","RAL_7012"=>"575e62","RAL_7013"=>"585346","RAL_7015"=>"4c5057","RAL_7016"=>"363d43","RAL_7021"=>"2e3236","RAL_7022"=>"464644","RAL_7023"=>"7f8279","RAL_7024"=>"484b52","RAL_7026"=>"484b52","RAL_7030"=>"919089","RAL_7031"=>"5b686f","RAL_7032"=>"b5b5a7","RAL_7033"=>"7a8376","RAL_7034"=>"928d75","RAL_7035"=>"c4caca","RAL_7036"=>"949294","RAL_7037"=>"7e8082","RAL_7038"=>"b0b3af","RAL_7039"=>"6d6b64","RAL_7040"=>"9aa0a7","RAL_7042"=>"929899","RAL_7043"=>"505455","RAL_7044"=>"bab9b0","RAL_8000"=>"8b7045","RAL_8001"=>"9c6935","RAL_8002"=>"774c3b","RAL_8003"=>"815333","RAL_8004"=>"904e3b","RAL_8007"=>"6b442a","RAL_8008"=>"735230","RAL_8011"=>"5b3927","RAL_8012"=>"64312a","RAL_8014"=>"49372a","RAL_8015"=>"5a2e2a","RAL_8016"=>"4f3128","RAL_8017"=>"45302b","RAL_8019"=>"3b3332","RAL_8022"=>"1e1a1a","RAL_8023"=>"a45c32","RAL_8024"=>"7b5741","RAL_8025"=>"765d4d","RAL_8028"=>"4f3b2b","RAL_9001"=>"eee9da","RAL_9002"=>"dadbd5","RAL_9003"=>"f8f9fb","RAL_9004"=>"252427","RAL_9005"=>"151619","RAL_9010"=>"f4f4ed","RAL_9011"=>"1f2126","RAL_9016"=>"f3f6f6","RAL_9017"=>"1b191d","RAL_9018"=>"cbd2d0");
*/
$ral=array( "RAL_1000"=>"c8ba80", "RAL_1001"=>"ceb181", "RAL_1002"=>"d2ad6b", "RAL_1003"=>"f6ac00", "RAL_1004"=>"e4a400", "RAL_1005"=>"c59300", "RAL_1006"=>"e49900", "RAL_1007"=>"e69100", "RAL_1011"=>"ab7f4b", "RAL_1012"=>"dcb52b", "RAL_1013"=>"e4dbc5", "RAL_1014"=>"dcc595", "RAL_1015"=>"e7d6b6", "RAL_1016"=>"f0e840", "RAL_1017"=>"f5ac48", "RAL_1018"=>"fad233", "RAL_1019"=>"a49077", "RAL_1020"=>"a09162", "RAL_1021"=>"f3bc00", "RAL_1023"=>"f8c000", "RAL_1024"=>"b79049", "RAL_1027"=>"a28411", "RAL_1028"=>"ffa200", "RAL_1032"=>"e0a700", "RAL_1033"=>"f69c00", "RAL_1034"=>"eda04e", "RAL_2000"=>"dd7100", "RAL_2001"=>"be4a22", "RAL_2002"=>"c2331c", "RAL_2003"=>"f77726", "RAL_2004"=>"ec5300", "RAL_2008"=>"ef6b1b", "RAL_2009"=>"e15105", "RAL_2010"=>"d1591a", "RAL_2011"=>"e97213", "RAL_2012"=>"d96148", "RAL_3000"=>"a91e1f", "RAL_3001"=>"9e1519", "RAL_3002"=>"9f161c", "RAL_3003"=>"860217", "RAL_3004"=>"6a121e", "RAL_3005"=>"571b24", "RAL_3007"=>"3f2224", "RAL_3009"=>"6a312d", "RAL_3011"=>"7a1c1f", "RAL_3012"=>"c6846d", "RAL_3013"=>"992923", "RAL_3014"=>"cc6e73", "RAL_3015"=>"de9aa4", "RAL_3016"=>"a93629", "RAL_3017"=>"cf4d5a", "RAL_3018"=>"cf384a", "RAL_3020"=>"be1110", "RAL_3022"=>"d26752", "RAL_3027"=>"b0133b", "RAL_3031"=>"a92d38", "RAL_4001"=>"855d81", "RAL_4002"=>"92394a", "RAL_4003"=>"cc598e", "RAL_4004"=>"681637", "RAL_4005"=>"7c6399", "RAL_4006"=>"942b6f", "RAL_4007"=>"472139", "RAL_4008"=>"8a4280", "RAL_4009"=>"9c838f", "RAL_4010"=>"c03573", "RAL_5000"=>"2d4a6e", "RAL_5001"=>"044662", "RAL_5002"=>"163279", "RAL_5003"=>"143154", "RAL_5004"=>"1c202a", "RAL_5005"=>"004785", "RAL_5007"=>"376289", "RAL_5008"=>"2c3943", "RAL_5009"=>"175874", "RAL_5010"=>"004579", "RAL_5011"=>"12273a", "RAL_5012"=>"1180b4", "RAL_5013"=>"1d3053", "RAL_5014"=>"637893", "RAL_5015"=>"0073af", "RAL_5017"=>"00518c", "RAL_5018"=>"00898c", "RAL_5019"=>"005682", "RAL_5020"=>"003e48", "RAL_5021"=>"007478", "RAL_5022"=>"222856", "RAL_5023"=>"45658b", "RAL_5024"=>"6090aa", "RAL_6000"=>"33735f", "RAL_6001"=>"296934", "RAL_6002"=>"2a5f2b", "RAL_6003"=>"4e533a", "RAL_6004"=>"0f4343", "RAL_6005"=>"0c4030", "RAL_6006"=>"3b3b31", "RAL_6007"=>"2e3725", "RAL_6008"=>"312f20", "RAL_6009"=>"243427", "RAL_6010"=>"416e32", "RAL_6011"=>"687f58", "RAL_6012"=>"2c3c37", "RAL_6013"=>"767557", "RAL_6014"=>"44402f", "RAL_6015"=>"383b32", "RAL_6016"=>"00674d", "RAL_6017"=>"4e8541", "RAL_6018"=>"4d9c35", "RAL_6019"=>"afcfaa", "RAL_6020"=>"3a4732", "RAL_6021"=>"829c78", "RAL_6022"=>"393526", "RAL_6024"=>"008152", "RAL_6025"=>"58713b", "RAL_6026"=>"00594c", "RAL_6027"=>"74b8b5", "RAL_6028"=>"305443", "RAL_6029"=>"006e3b", "RAL_6032"=>"007e4e", "RAL_6033"=>"3e857d", "RAL_6034"=>"72aaa8", "RAL_7000"=>"76848a", "RAL_7001"=>"8d959b", "RAL_7002"=>"827b63", "RAL_7003"=>"767465", "RAL_7004"=>"979799", "RAL_7005"=>"6b6f6c", "RAL_7006"=>"75685a", "RAL_7008"=>"76623f", "RAL_7009"=>"585c51", "RAL_7010"=>"575a55", "RAL_7011"=>"51585b", "RAL_7012"=>"575d5e", "RAL_7013"=>"555042", "RAL_7015"=>"4e5157", "RAL_7016"=>"363d41", "RAL_7021"=>"2f3335", "RAL_7022"=>"474540", "RAL_7023"=>"7c7e73", "RAL_7024"=>"44494f", "RAL_7026"=>"343f41", "RAL_7030"=>"8d8a81", "RAL_7031"=>"5a666b", "RAL_7032"=>"b3af9c", "RAL_7033"=>"797f72", "RAL_7034"=>"90876d", "RAL_7035"=>"c1c5c0", "RAL_7036"=>"928e8c", "RAL_7037"=>"7a7c7a", "RAL_7038"=>"acaea6", "RAL_7039"=>"6c6961", "RAL_7040"=>"969da1", "RAL_7042"=>"8d9191", "RAL_7043"=>"4d5150", "RAL_7044"=>"b6b2a6", "RAL_7045"=>"8c9194", "RAL_7046"=>"7c8387", "RAL_7047"=>"c6c6c5", "RAL_8000"=>"86693c", "RAL_8001"=>"9c6429", "RAL_8002"=>"754836", "RAL_8003"=>"7e4e28", "RAL_8004"=>"8c4832", "RAL_8007"=>"684125", "RAL_8008"=>"734e29", "RAL_8011"=>"593827", "RAL_8012"=>"63332d", "RAL_8014"=>"483626", "RAL_8015"=>"5b302b", "RAL_8016"=>"4d3026", "RAL_8017"=>"402b25", "RAL_8019"=>"3b3332", "RAL_8022"=>"201a18", "RAL_8023"=>"a4592d", "RAL_8024"=>"7a543b", "RAL_8025"=>"735644", "RAL_8028"=>"4f3b2d", "RAL_9001"=>"ede3d3", "RAL_9002"=>"d7d6ca", "RAL_9003"=>"edede7", "RAL_9004"=>"262627", "RAL_9005"=>"121314", "RAL_9006"=>"a6abb5", "RAL_9007"=>"7d7a78", "RAL_9010"=>"f1eee2", "RAL_9011"=>"212326", "RAL_9016"=>"edeee8", "RAL_9017"=>"1d1c1d", "RAL_9018"=>"c6ccc4");
//* da RAL a RGB o HTML o % di colore abbastanza preciso, salvo sfalsamenti dovuti al monitor o al browes
//* l'operazione inversa al contrario può dare anche valori molto discordanti
//valore per il calcolo del range RGB --> RAL da RGB o HTML
$delta=20;//eventualmente modificare per allargare o restirngere il campo di ricerca
//funzione per la ricerca del RAL più vicino, se esiste
function verifica($array,$val,$prC){//array di RAL, valore colore immesso, valore per calcolo range
$valore=$val;//è il colore in esadecimale (HTML) inserito
//suddivido i valori e li riduco a RGB
$rosso=$valore[0].$valore[1];
$verde=$valore[2].$valore[3];
$blu=$valore[4].$valore[5];
$rosso=(int)base_convert($rosso, 16, 10);//da esadecimale a decimale
$verde=(int)base_convert($verde, 16, 10);
$blu=(int)base_convert($blu, 16, 10);
//faccio un range di colori +- delta% per colori ricerca simili
$delta=$prC;
$deltaMeno=(100-$delta)/100;
$deltaPiu=(100+$delta)/100;
//echo "delta min Max $deltaMeno $deltaPiu<br>";
//introduco una correzione anche per avere range agli estremi
$corrR=0;
$corrV=0;
$corrB=0;
if(($rosso>=0 && $rosso <=21) || ($rosso>=234 && $rosso <=255)){
$corrR=round(sqrt(abs((0.0158*pow($rosso, 2)-4.0185*$rosso+193.99))));
}
if(($verde>=0 && $verde <=21) || ($verde>=234 && $verde <=255)){
$corrV=round(sqrt(abs((0.0158*pow($verde, 2)-4.0185*$verde+193.99))));
}
if(($blu>=0 && $blu <=21) || ($blu>=234 && $blu <=255)){
$corrB=round(sqrt(abs((0.0158*pow($blu, 2)-4.0185*$blu+193.99))));
}
//echo "correzione R= $corrR - V= $corrV - B= $corrB<br>";
//calcolo l'intervallo di colore RGB troncando all'intero
$rossoMin=(int)(($rosso-$corrR)*$deltaMeno);
$rossoMax=(int)(($rosso+$corrR)*$deltaPiu);
$verdeMin=(int)(($verde-$corrV)*$deltaMeno);
$verdeMax=(int)(($verde+$corrV)*$deltaPiu);
$bluMin=(int)(($blu-$corrB)*$deltaMeno);
$bluMax=(int)(($blu+$corrB)*$deltaPiu);
//riporto entro il range 0 - 255
if($rossoMin<0){$rossoMin=0;}
if($rossoMax>255){$rossoMax=255;}
if($verdeMin<0){$verdeMin=0;}
if($verdeMax>255){$verdeMax=255;}
if($bluMin<0){$bluMin=0;}
if($bluMax>255){$bluMax=255;}
//echo "rosso min Max $rossoMin $rossoMax<br>";
//echo "verde min Max $verdeMin $verdeMax<br>";
//echo "blu min Max $bluMin $bluMax<br>";
//preparo la frase non trovati
$testo="non trovati";
$testo1="";
//comincio a ciclare gli array
$trKey=array();
$trVal=array();
$conta=0;
foreach ($array as $key1 => $val1) {//cilo l'array e trasferisco i valori
$trKey[$conta]=$key1;//nome del RAL
$trVal[$conta]=$val1;//valore HTML del RAL
$conta++;
}//fine foreach
$quanti=sizeof($trKey);//se eventualmente aggiungere RAL
for($k=0; $k<$quanti;$k++){
$tr=$trVal[$k];
$trRossoE=$tr[0].$tr[1];//esa del rosso
$trVerdeE=$tr[2].$tr[3];//esa del verde
$trBluE=$tr[4].$tr[5];//esa del blu
$trRosso=(int)base_convert($trRossoE, 16, 10);//riporto a RGB
$trVerde=(int)base_convert($trVerdeE, 16, 10);
$trBlu=(int)base_convert($trBluE, 16, 10);
//echo "tr R V B $trRosso $trVerde $trBlu<br>";
if($valore === $trVal[$k]){//trovato valore esadecimale del RAL = all'immesso
$key0=$trKey[$k];
$testo1="<span style=\"background-color:#".$trVal[$k]."\">$key0</span>";
break;//poso uscire
}else{//non ho trovato corrispondenza esatta, filtro tra gli intervalli
if($trRosso>=$rossoMin & $trRosso<=$rossoMax){//range rosso
//echo "range rosso ".$rossoMin." ".$trRosso." ".$rossoMax."<br>";
if($trVerde>=$verdeMin & $trVerde<=$verdeMax){// range verde
//echo "range verde ".$verdeMin." ".$trVerde." ".$verdeMax."<br>";
if($trBlu>=$bluMin & $trBlu<=$bluMax){//range blu
//echo "range blu ".$bluMin." ".$trBlu." ".$bluMax."<br>";
$testo1.="<span style=\"background-color:#".$trVal[$k]."\">".$trKey[$k]."</span> ";
}//fine intervallo blu
}//fine if intervallo verde
}//fine if intervallo rosso
}//fine if else valore immesso
}//fine for
if($testo1 !=""){
$testo=$testo1;
}else{
$spanR="<span style=\"background-color:#ff0000; color:#ffffff;\">";
$spanV="<span style=\"background-color:#00ff00; color:#ffffff;\">";
$spanB="<span style=\"background-color:#0000ff; color:#ffffff;\">";
$testo=$testo."<span style=\"font-size:12px;\"> nel range <br><b>$spanR R=[$rossoMin÷$rossoMax]</span>$spanV G=[$verdeMin÷$verdeMax]</span>$spanB B=[$bluMin÷$bluMax]</span></b></span>";
}
return "<span style=\"font-size:12px\">valori approssimati<br>".$testo."</span><br>";
}//fine function
//*visualizza valori e colore*************************************************************************
if(isset($_POST['invia']) && $_POST['invia']=="invia"){
$scelta=$_POST['scelta'];//cosa ho scelto
$controllo=1;//per la verifica dei dati introdotti
$all1=0;//dalla partenza
$all2=0;
$all3=0;
$all4=0;
switch($scelta){
case "PC";
//sistemo il chek
$_SESSION['PC']="checked";
$_SESSION['DE']="";
$_SESSION['ES']="";
$_SESSION['RA']="";
//leggo valori percentuali
$rossoPC=trim($_POST['rossoPC']);
$verdePC=trim($_POST['verdePC']);
$bluPC=trim($_POST['bluPC']);
//verifico dati introdotti
if($rossoPC=="" || $rossoPC<0 || $rossoPC>100){$controllo=0;}
if($verdePC=="" || $verdePC<0 || $verdePC>100){$controllo=0;}
if($bluPC=="" || $bluPC<0 || $bluPC>100){$controllo=0;}
if($controllo==1){//dati introdotti OK
$rossoPC=(int)$rossoPC;
$verdePC=(int)$verdePC;
$bluPC=(int)$bluPC;
$neroPC=100-($rossoPC+$verdePC+$bluPC)/3;
$tot=$rossoPC+$verdePC+$bluPC+$neroPC;
$rossoPCC=100-(int)$rossoPC;
$verdePCC=100-(int)$verdePC;
$bluPCC=100-(int)$bluPC;
$rossoDE=(int)($rossoPC*255/100);
$verdeDE=(int)($verdePC*255/100);
$bluDE=(int)($bluPC*255/100);
$rossoDEC=255-(int)($rossoPC*255/100);//calcolo colore complementare
$verdeDEC=255-(int)($verdePC*255/100);
$bluDEC=255-(int)($bluPC*255/100);
$rossoES=base_convert($rossoDE, 10, 16);
$verdeES=base_convert($verdeDE, 10, 16);
$bluES=base_convert($bluDE, 10, 16);
if(strlen($rossoES)<2){$rossoES="0".$rossoES;}
if(strlen($verdeES)<2){$verdeES="0".$verdeES;}
if(strlen($bluES)<2){$bluES="0".$bluES;}
$bck=$rossoES.$verdeES.$bluES;//colore primario
$valoreRal=str_replace("RAL_"," ",verifica($ral,$bck,$delta));//cerco il RAL
$rossoESC=base_convert($rossoDEC, 10, 16);
$verdeESC=base_convert($verdeDEC, 10, 16);
$bluESC=base_convert($bluDEC, 10, 16);
if(strlen($rossoESC)<2){$rossoESC="0".$rossoESC;}//riporto esa a due caratteri
if(strlen($verdeESC)<2){$verdeESC="0".$verdeESC;}
if(strlen($bluESC)<2){$bluESC="0".$bluESC;}
$bckC=$rossoESC.$verdeESC.$bluESC;//colore complementare
$all1=1;
}else{//valori introdotti non corretti
echo "<div id=\"errore\"><h3>uno o più valori inseriti errati<br>riinserire</h3></div>";
echo "<meta http-equiv='Refresh' content='3; URL=http://www.pdagrafica.com/Personale/test/pda/conversioneDecEsa04.php'>";
}
break;
case "DE";
//sistemo il chek
$_SESSION['PC']="";
$_SESSION['DE']="checked";
$_SESSION['ES']="";
$_SESSION['RA']="";
//leggo valori decimali RGB
$rossoDE=trim($_POST['rossoDE']);
$verdeDE=trim($_POST['verdeDE']);
$bluDE=trim($_POST['bluDE']);
//verifico dati introdotti
if($rossoDE=="" || $rossoDE<0 || $rossoDE>255){$controllo=0;}
if($verdeDE=="" || $verdeDE<0 || $verdeDE>255){$controllo=0;}
if($bluDE=="" || $bluDE<0 || $bluDE>255){$controllo=0;}
if($controllo==1){//dati introdotti OK
$rossoDE=(int)$rossoDE;
$verdeDE=(int)$verdeDE;
$bluDE=(int)$bluDE;
//calcolo colore complementare
$rossoDEC=255-(int)$rossoDE;
$verdeDEC=255-(int)$verdeDE;
$bluDEC=255-(int)$bluDE;
$rossoPC=(int)($rossoDE*100/255);
$verdePC=(int)($verdeDE*100/255);
$bluPC=(int)($bluDE*100/255);
$rossoPCC=100-$rossoPC;
$verdePCC=100-$verdePC;
$bluPCC=100-$bluPC;
$rossoES=base_convert($rossoDE, 10, 16);
$verdeES=base_convert($verdeDE, 10, 16);
$bluES=base_convert($bluDE, 10, 16);
if(strlen($rossoES)<2){$rossoES="0".$rossoES;}//riporto esa a due caratteri
if(strlen($verdeES)<2){$verdeES="0".$verdeES;}
if(strlen($bluES)<2){$bluES="0".$bluES;}
$bck=$rossoES.$verdeES.$bluES;//colore primario
$valoreRal=str_replace("RAL_"," ",verifica($ral,$bck,$delta));//ricerca RAL
$rossoESC=base_convert($rossoDEC, 10, 16);
$verdeESC=base_convert($verdeDEC, 10, 16);
$bluESC=base_convert($bluDEC, 10, 16);
if(strlen($rossoESC)<2){$rossoESC="0".$rossoESC;}//riporto esa a due caratteri
if(strlen($verdeESC)<2){$verdeESC="0".$verdeESC;}
if(strlen($bluESC)<2){$bluESC="0".$bluESC;}
$bckC=$rossoESC.$verdeESC.$bluESC;//colore complementare
$all2=1;
}else{//dati introdotti non corretti
echo "<div id=\"errore\"><h3>uno o più valori inseriti errati<br>riinserire</h3></div>";
echo "<meta http-equiv='Refresh' content='3; URL=http://www.pdagrafica.com/Personale/test/pda/conversioneDecEsa04.php'>";
}
break;
case "ES";
//sistemo il chek
$_SESSION['PC']="";
$_SESSION['DE']="";
$_SESSION['ES']="checked";
$_SESSION['RA']="";
//leggo valori esadecimali
$rossoES=strtolower(trim($_POST['rossoES']));
$verdeES=strtolower(trim($_POST['verdeES']));
$bluES=strtolower(trim($_POST['bluES']));
//verifico dati introdotti
if($rossoES=="" || !eregi("^([0-9A-F]{1,2})$",$rossoES)){$controllo=0;}
if($verdeES=="" || !eregi("^([0-9A-F]{1,2})$",$verdeES)){$controllo=0;}
if($bluES=="" || !eregi("^([0-9A-F]{1,2})$",$bluES)){$controllo=0;}
if($controllo==1){//dati introdotti OK
if(strlen($rossoES)<2){$rossoES="0".$rossoES;}//riporto esa a due caratteri
if(strlen($verdeES)<2){$verdeES="0".$verdeES;}
if(strlen($bluES)<2){$bluES="0".$bluES;}
$rossoDE=base_convert($rossoES, 16, 10);
$verdeDE=base_convert($verdeES, 16, 10);
$bluDE=base_convert($bluES, 16, 10);
$rossoDEC=255-(int)$rossoDE;
$verdeDEC=255-(int)$verdeDE;
$bluDEC=255-(int)$bluDE;
$rossoPC=(int)($rossoDE*100/255);
$verdePC=(int)($verdeDE*100/255);
$bluPC=(int)($bluDE*100/255);
//calcolo colore complementare
$rossoPCC=100-(int)($rossoDE*100/255);
$verdePCC=100-(int)($verdeDE*100/255);
$bluPCC=100-(int)($bluDE*100/255);
$bck=$rossoES.$verdeES.$bluES;//colore primario
$valoreRal=str_replace("RAL_"," ",verifica($ral,$bck,$delta));//ricerco ral
$rossoESC=base_convert($rossoDEC, 10, 16);
$verdeESC=base_convert($verdeDEC, 10, 16);
$bluESC=base_convert($bluDEC, 10, 16);
if(strlen($rossoESC)<2){$rossoESC="0".$rossoESC;}//riporto esa a due caratteri
if(strlen($verdeESC)<2){$verdeESC="0".$verdeESC;}
if(strlen($bluESC)<2){$bluESC="0".$bluESC;}
$bckC=$rossoESC.$verdeESC.$bluESC;//colore complementare
$all3=1;
}else{//dati non corretti
echo "<div id=\"errore\"><h3>uno o più valori inseriti errati<br>riinserire</h3></div>";
echo "<meta http-equiv='Refresh' content='3; URL=http://www.pdagrafica.com/Personale/test/pda/conversioneDecEsa04.php'>";
}
break;
case "RA";
//sistemo il chek
$_SESSION['PC']="";
$_SESSION['DE']="";
$_SESSION['ES']="";
$_SESSION['RA']="checked";
//leggo valore RAL
$coloreRal=$_POST['ral'];//leggo valore esa e valore ral = 000000*RAL_xyz
$esp=explode("*",$coloreRal);
$bck=$esp[0];//valore esadecimale colore primario
$valoreRal=str_replace("_"," ",$esp[1]); //RAL xyz
$rossoES=$bck[0].$bck[1];
$verdeES=$bck[2].$bck[3];
$bluES=$bck[4].$bck[5];
$rossoDE=base_convert($rossoES, 16, 10);
$verdeDE=base_convert($verdeES, 16, 10);
$bluDE=base_convert($bluES, 16, 10);
//calcolo colore complementare
$rossoDEC=255-(int)$rossoDE;
$verdeDEC=255-(int)$verdeDE;
$bluDEC=255-(int)$bluDE;
$rossoPC=(int)($rossoDE*100/255);
$verdePC=(int)($verdeDE*100/255);
$bluPC=(int)($bluDE*100/255);
$rossoPCC=100-(int)($rossoDE*100/255);
$verdePCC=100-(int)($verdeDE*100/255);
$bluPCC=100-(int)($bluDE*100/255);
$rossoESC=base_convert($rossoDEC, 10, 16);
$verdeESC=base_convert($verdeDEC, 10, 16);
$bluESC=base_convert($bluDEC, 10, 16);
if(strlen($rossoESC)<2){$rossoESC="0".$rossoESC;}//riporto esa a due cifre
if(strlen($verdeESC)<2){$verdeESC="0".$verdeESC;}
if(strlen($bluESC)<2){$bluESC="0".$bluESC;}
$bckC=$rossoESC.$verdeESC.$bluESC;//colore complementare
$all4=1;
break;
}//fine switch
if($controllo==1){//visualizzo i risultati
?>
<div id="vedi">
<?php
if($all1==0){$all1="left";}else{$all1="right";}
if($all2==0){$all2="left";}else{$all2="right";}
if($all3==0){$all3="left";}else{$all3="right";}
if($all4==0){$all4="left";}else{$all4="right";}
?>
<table width="550" border="0" align="center" cellpadding="0" cellspacing="4" style="background-color:#CCCCCC; ">
<tr valign="middle">
<td colspan="5" style="background-color:#FFFFFF; color:#000000; font-weight:bold; ">colore primario</td>
<td align="right" style="background-color: #FFFFFF; "> </td>
</tr>
<tr valign="middle">
<td width="27%"> </td>
<td width="13%" align="center" style="background-color: #FF0000; color:#FFFFFF; font-weight: bold;">rosso</td>
<td width="13%" align="center" style="background-color: #00FF00; color:#FFFFFF; font-weight: bold;">verde</td>
<td colspan="2" align="center" style="background-color: #0000FF; color:#FFFFFF; font-weight: bold;">blu</td>
<td width="35%" rowspan="4" style="background-color:<?php echo "#".$bck;?>"> </td>
</tr>
<tr valign="middle">
<td align="<?php echo $all1;?>">% di </td>
<td align="center"><?php echo $rossoPC;?></td>
<td align="center"><?php echo $verdePC;?></td>
<td colspan="2" align="center"><?php echo $bluPC;?></td>
</tr>
<tr valign="middle">
<td align="<?php echo $all2;?>">RGB </td>
<td align="center"><?php echo $rossoDE;?></td>
<td align="center"><?php echo $verdeDE;?></td>
<td colspan="2" align="center"><?php echo $bluDE;?></td>
</tr>
<tr valign="middle">
<td align="<?php echo $all3;?>">HTML #</td>
<td align="center"><?php echo $rossoES;?></td>
<td align="center"><?php echo $verdeES;?></td>
<td colspan="2" align="center"><?php echo $bluES;?></td>
</tr>
<tr valign="middle">
<?php
$range="<span class=\"Stile10\">(±$delta% su RGB) </span>";
if($scelta=="RA"){$range="";}
?>
<td style="background-color: #999999; font-size: 12px; " align="<?php echo $all4;?>">RAL classic <?php echo $range;?></td>
<td colspan="5" align="left" style="background-color: #999999;"><?php echo $valoreRal;?></td>
</tr>
<tr valign="middle">
<td colspan="6" style="background-color:#000000; color: #FFFFFF; font-weight: bold;">colore complementare</td>
</tr>
<tr valign="middle">
<td> </td>
<td align="center" style="background-color: #00ffff;">ciano</td>
<td align="center" style="background-color: #ff00ff;">magenta</td>
<td colspan="2" align="center" style="background-color: #ffff00;">giallo</td>
<td rowspan="4" style="background-color:<?php echo "#".$bckC;?>"> </td>
</tr>
<tr valign="middle">
<td>% di </td>
<td align="center"><?php echo $rossoPCC;?></td>
<td align="center"><?php echo $verdePCC;?></td>
<td colspan="2" align="center"><?php echo $bluPCC;?></td>
</tr>
<tr valign="middle">
<td style="font-size: 12px;">decimale RGB </td>
<td align="center"><?php echo $rossoDEC;?></td>
<td align="center"><?php echo $verdeDEC;?></td>
<td colspan="2" align="center"><?php echo $bluDEC;?></td>
</tr>
<tr valign="middle">
<td style="font-size: 12px;">esadecimale HTML </td>
<td align="center"><?php echo $rossoESC;?></td>
<td align="center"><?php echo $verdeESC;?></td>
<td colspan="2" align="center"><?php echo $bluESC;?></td>
</tr>
</table>
<tr valign="middle">
<?php
$range="<span class=\"Stile10\">(±$delta% su RGB) </span>";
if($scelta=="RA"){$range="";}
?>
<td bgcolor="#999999" align="<?php echo $all4;?>"><span class="Stile2">RAL classic <?php echo $range;?></span></td>
<td colspan="5" align="left" bgcolor="#999999"><?php echo $valoreRal;?></td>
</tr>
<tr valign="middle">
<td colspan="6" bgcolor="#000000"><span class="Stile1">colore complementare</span></td>
</tr>
<tr valign="middle">
<td> </td>
<td align="center" bgcolor="#00ffff">ciano</td>
<td align="center" bgcolor="#ff00ff">magenta</td>
<td colspan="2" align="center" bgcolor="#ffff00">giallo</td>
<td rowspan="4" bgcolor="<?php echo "#".$bckC;?>"> </td>
</tr>
<tr valign="middle">
<td>% di </td>
<td align="center"><?php echo $rossoPCC;?></td>
<td align="center"><?php echo $verdePCC;?></td>
<td colspan="2" align="center"><?php echo $bluPCC;?></td>
</tr>
<tr valign="middle">
<td><span class="Stile2">decimale</span> RGB </td>
<td align="center"><?php echo $rossoDEC;?></td>
<td align="center"><?php echo $verdeDEC;?></td>
<td colspan="2" align="center"><?php echo $bluDEC;?></td>
</tr>
<tr valign="middle">
<td><span class="Stile2">esadecimale </span>HTML </td>
<td align="center"><?php echo $rossoESC;?></td>
<td align="center"><?php echo $verdeESC;?></td>
<td colspan="2" align="center"><?php echo $bluESC;?></td>
</tr>
</table>
</div>
<?php
}//fine if controllo
}//fine if post
?>
<div id="entra">
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<table width="550" border="0" align="center" cellpadding="0" cellspacing="2" style="background-color:#CCCCCC;">
<tr>
<td colspan="5" style="background-color:#666666;"><strong>Conversione valori colori e loro complementari</strong></td>
<td align="right" style="background-color:#666666;"> </td>
</tr>
<tr>
<td width="27%"> </td>
<td width="13%" align="center" valign="middle" style="background-color:#FF0000; color: #FFFFFF; font-weight: bold;">rosso</td>
<td width="13%" align="center" valign="middle" style="background-color:#00FF00; color: #FFFFFF; font-weight: bold;">verde</td>
<td width="13%" align="center" valign="middle" style="background-color:#0000FF; color: #FFFFFF; font-weight: bold;">blu</td>
<td colspan="2" align="right" valign="middle" style="font-size:12px; font-weight:bold; text-align:right;" >seleziona quali valori partenza</td>
</tr>
<tr>
<td align="left" valign="middle">RGB % di </td>
<td align="center" valign="middle"><input name="rossoPC" type="text" id="col" value="0" size="3" maxlength="3"></td>
<td align="center" valign="middle"><input name="verdePC" type="text" id="col" value="0" size="3" maxlength="3"></td>
<td align="center" valign="middle"><input name="bluPC" type="text" id="col" value="0" size="3" maxlength="3"></td>
<td width="14%" align="right" valign="middle" style="font-size:12px;">da RGB
<input name="scelta" type="radio" value="PC"<?php echo $_SESSION['PC'];?>></td>
<td width="20%" valign="middle" style="font-size:12px;">inserire da 0 a 100</td>
</tr>
<tr>
<td align="left" valign="middle" style="font-size:12px;">decimale HSL </td>
<td align="center" valign="middle"><input name="rossoDE" type="text" id="col" value="0" size="3" maxlength="3"></td>
<td align="center" valign="middle"><input name="verdeDE" type="text" id="col" value="0" size="3" maxlength="3"></td>
<td align="center" valign="middle"><input name="bluDE" type="text" id="col" value="0" size="3" maxlength="3"></td>
<td align="right" valign="middle" style="font-size:12px;">da HSL
<input name="scelta" type="radio" value="DE" <?php echo $_SESSION['DE'];?>></td>
<td valign="middle" style="font-size:12px;">inserire da 0 a 255 </td>
</tr>
<tr>
<td align="left" valign="middle" style="font-size:12px;">esadecimale HTML </td>
<td align="center" valign="middle"><input name="rossoES" type="text" id="col" value="0" size="2" maxlength="2"></td>
<td align="center" valign="middle"><input name="verdeES" type="text" id="col" value="0" size="2" maxlength="2"></td>
<td align="center" valign="middle"><input name="bluES" type="text" id="col" value="0" size="2" maxlength="2"></td>
<td align="right" valign="middle" style="font-size:12px;">da HTML<input name="scelta" type="radio" value="ES"<?php echo $_SESSION['ES'];?>></td>
<td valign="middle" style="font-size:12px;">inserire da 0 a FF </td>
</tr>
<tr valign="middle">
<td><p> RAL classic </p>
</td>
<td colspan="2" align="left">
<select name="ral">
<?php
foreach ($ral as $key => $val) {
?>
<option value="<?php echo $val."*".$key; ?>" style="background-color: <?php echo "#".$val; ?>"><?php echo str_replace("_"," ",$key); ?></option>
<?php
}//fine foreach
?>
</select>
</td>
<td> </td>
<td align="right" style="font-size:12px;">da RAL<input name="scelta" type="radio" value="RA" <?php echo $_SESSION['RA'];?>></td>
<td style="font-size:12px;">
RAL1000÷RAL9018</td>
</tr>
<tr>
<td valign="top"> </td>
<td valign="top"> </td>
<td valign="top"> </td>
<td valign="top"> </td>
<td colspan="2" valign="bottom">
<input name="invia" type="submit" id="invia" value="invia">
</td>
</tr>
<tr>
<td valign="top"> </td>
<td valign="top"> </td>
<td valign="top"> </td>
<td valign="top"> </td>
<td colspan="2" valign="bottom">
<input type="reset" name="Submit" value="reset">
</td>
</tr>
<tr>
<td colspan="6" valign="top" style="font-size:12px;"><p>I valori "<strong>% di</strong>" vengono troncati all'intero<br>
Il colore RAL potrebbe non essere accurato in quanto spesso sfalsato dal monitor e dal browser utilizzati.<br>
La ricerca (range) del RAL più vicino avviene cercando i RAL con ±<?php echo $delta;?>% dei colori RGB (mod. riga 115), con una correzione per i valori estremi. Si possono ottenere più valori.<br>
Se non viene trovato il valore del RAL conviene operare all'inverso cercando tra i RAL il colore che più si avvicina a quello mostrato. <br>
</p>
<!-- se vuoi questa parte puoi anche toglierla da<p...> a </p>-->
<p class="Stile5">powerd by gianni -<span class="Stile4"><a href="http://www.borgo-italia.it/" target="_blank"> borgo</a></span><a href="http://www.borgo-italia.it/"><span class="Stile3">-</span><span class="Stile4">italia</span></a> - rev. 04</p></td>
</tr>
</table>
</form>
</div>
</div>