=$B) $h=60.0*($G-$B)/($max-$min); else if ($max==$R && $G<$B) $h=60.0*($G-$B)/($max-$min)+360.0; else if ($max==$G) $h=60.0*($B-$R)/($max-$min)+120.0; else if ($max==$B) $h=60.0*($R-$G)/($max-$min)+240.0; $s = $max==0 ? 0 : ($max-$min)/$max; $v = $max; return array("h"=>$h,"s"=>$s,"v"=>$v); } function hsv2rgb( $H, $S, $V ) { $Hi=(int)floor($H/60.0)%6; $f=$H/60-$Hi; $p=$V*(1-$S); $q=$V*(1-$f*$S); $t=$V*(1-(1-$f)*$S); switch ($Hi) { case 0: $R=$V;$G=$t;$B=$p;break; case 1: $R=$q;$G=$V;$B=$p;break; case 2: $R=$p;$G=$V;$B=$t;break; case 3: $R=$p;$G=$q;$B=$V;break; case 4: $R=$t;$G=$p;$B=$V;break; case 5: $R=$V;$G=$p;$B=$q;break; } $r=$R*255; $g=$G*255; $b=$B*255; return array("r"=>$r,"g"=>$g,"b"=>$b); } function textorize2($img, $text, $nLines, $fontScale, $colourAdjustment) { /* we need a table of character widths. Ugly, but it does'nt seen we can * do better than that in SVG for this purpose. TODO use the sera SVG font * and parse the file to retrieve * each character's widths */ /* checks limits of parametres */ if ($nLines > MAXNLINES) $nLines=MAXNLINES; $Width=imagesx($img); $Height=imagesy($img); $fontSize=$fontScale*$Height/$nLines; $CharWidths=array( // " "=>651/2048.0, " "=>500/2048.0, "!"=>821/2048.0, "\""=>942/2048.0, "\#"=>1716/2048.0, "\$"=>1303/2048.0, "%"=>1946/2048.0, "&"=>1597/2048.0, "'"=>563/2048.0, "("=>799/2048.0, ")"=>799/2048.0, "*"=>1024/2048.0, "+"=>1716/2048.0, ","=>651/2048.0, "-"=>739/2048.0, "."=>651/2048.0, "/"=>690/2048.0, "0"=>1303/2048.0, "1"=>1303/2048.0, "2"=>1303/2048.0, "3"=>1303/2048.0, "4"=>1303/2048.0, "5"=>1303/2048.0, "6"=>1303/2048.0, "7"=>1303/2048.0, "8"=>1303/2048.0, "9"=>1303/2048.0, ":"=>690/2048.0, ";"=>690/2048.0, "<"=>1716/2048.0, "="=>1716/2048.0, ">"=>1716/2048.0, "?"=>1087/2048.0, "@"=>2048/2048.0, "A"=>1401/2048.0, "B"=>1405/2048.0, "C"=>1430/2048.0, "D"=>1577/2048.0, "E"=>1294/2048.0, "F"=>1178/2048.0, "G"=>1587/2048.0, "H"=>1540/2048.0, "I"=>604/2048.0, "J"=>604/2048.0, "K"=>1343/2048.0, "L"=>1141/2048.0, "M"=>1767/2048.0, "N"=>1532/2048.0, "O"=>1612/2048.0, "P"=>1235/2048.0, "Q"=>1612/2048.0, "R"=>1423/2048.0, "S"=>1300/2048.0, "T"=>1251/2048.0, "U"=>1499/2048.0, "V"=>1401/2048.0, "W"=>2025/2048.0, "X"=>1403/2048.0, "Y"=>1251/2048.0, "Z"=>1403/2048.0, "["=>799/2048.0, "\\"=>690/2048.0, "]"=>799/2048.0, "^"=>1716/2048.0, "_"=>1024/2048.0, "`"=>1024/2048.0, "a"=>1255/2048.0, "b"=>1300/2048.0, "c"=>1126/2048.0, "d"=>1300/2048.0, "e"=>1260/2048.0, "f"=>721/2048.0, "g"=>1300/2048.0, "h"=>1298/2048.0, "i"=>569/2048.0, "j"=>569/2048.0, "k"=>1186/2048.0, "l"=>569/2048.0, "m"=>1995/2048.0, "n"=>1298/2048.0, "o"=>1253/2048.0, "p"=>1300/2048.0, "q"=>1300/2048.0, "r"=>842/2048.0, "s"=>1067/2048.0, "t"=>803/2048.0, "u"=>1298/2048.0, "v"=>1212/2048.0, "w"=>1675/2048.0, "x"=>1212/2048.0, "y"=>1212/2048.0, "z"=>1075/2048.0, "{"=>1303/2048.0, "|"=>690/2048.0, "}"=>1303/2048.0, "~"=>1716/2048.0); $output=" Bitmap to Letters demo "; // Nice Bold Fonts: //American Typewriter //Arial Black, Bernard MT condensed, Cooper Black, Futura Condensed Extra Bold, Gill Sans, //Gill Sans Ultra Bold, Haettenschweiler, Helvetica Bold, Impact, Rockwell Bold, Rockwell Extra Bold //Tahoma, Verdana Bold $text=trim(utf8_decode($text))." "; $nbletters=strlen($text); if ($nbletters==0) { $text="no text provided"; $nbletters=strlen($text); } $ti=0; for ($line=0;$line<$nLines;$line++) { $realY = $Height*($line+1.0)/$nLines; $y= (int)floor($realY-$Height/(2*$nLines)); $rx=1; // skip any white space at the beginning of the line while ($text[$ti%$nbletters] == ' ') $ti++; while ($rx<$Width) { $x=(int)floor($rx)-1; $scale=2-((rAt($img,$x,$y)+gAt($img,$x,$y)+bAt($img,$x,$y))/(3*256.0)); $c=$text[$ti%$nbletters]; if ($c < ' ' || $c > '~') $c='?'; // we only support ascii :-( $r=rAt($img,$x,$y); $g=gAt($img,$x,$y); $b=bAt($img,$x,$y); if ($r+$g+$b<3*255) { /* eliminate white */ if ($colourAdjustment > 0) { /* increase the colour's saturation to compensate for mixing with white background */ $hsv=rgb2hsv($r,$g,$b); $h=$hsv['h']; $s=$hsv['s']; $v=$hsv['v']; if ($s!=0) { $s=($s+$colourAdjustment)>1.0?1.0:($s+$colourAdjustment); $rgb=hsv2rgb($h,$s,$v); $r=$rgb["r"]; $g=$rgb["g"]; $b=$rgb["b"]; } } // $charToPrint=($c=='&')?"&":($c=='<')?"<":($c=='>')?">":$c; if ($c=='&') $charToPrint='&'; else if ($c=='<') $charToPrint='<'; else if ($c=='>') $charToPrint='>'; else $charToPrint=$c; $output.=sprintf("%s\n",$rx,$realY,$fontSize*$scale,$r,$g,$b,$charToPrint); $rx+=$scale*$CharWidths[$c]*$fontSize; $ti++; /* next letter */ } else /* advance one em */ $rx+=$scale*$CharWidths['m']*$fontSize; } } // framing rectangle. Should be a clipping path, but no FF support $outerFrameWidth=200; $innerFrameWidth=2; $r=($outerFrameWidth-$innerFrameWidth)/2; $output.=" "; return $output; } ?>