4) { $digit03 = $_GET['digit03']; $sigDigits = trim($sigDigits) . trim($digit03); } $multiplier = $_GET['multiplier']; $totVal = $sigDigits * $multiplier; if ($totVal / 1000000 > 1) { $totVal = ($totVal / 1000000) . "M"; } else if ($totVal / 1000 > 1 ) { $totVal = ($totVal / 1000) . "K"; } $tolerance = $_GET['tolerance']; $outStr = $totVal . ", +/-" . $tolerance . "%"; if ($numBands > 5) { $tmpCoeff = $_GET['tmpCoeff']; $outStr = $outStr . ", " . $tmpCoeff . "PPM/C"; } #--------------------------------------- $img_handle = imagecreatetruecolor($imageWidth,$imageHeight + $txtHeight); # define a font and get the biggest size that fits in our available space $dotFont = "images/OldSansBlack"; $font_size = 33; do { $font_size--; $bbox=imagettfbbox ($font_size, 0, $dotFont, $outStr); $right_text = $bbox[2]; // right co-ordinate $left_text = $bbox[0]; // left co-ordinate $width_text = $right_text - $left_text; $height_text = abs($bbox[7] - $bbox[1]); } while ($height_text > $txtHeight || $width_text > $imageWidth ); $textXOffset = ($imageWidth - $width_text) / 2; # Define some colors $ResColor = ImageColorAllocate ($img_handle,255,255,205); $Black = ImageColorAllocate ($img_handle, 0,0,0); $Brown = ImageColorAllocate ($img_handle,105,50,50); $Red = ImageColorAllocate ($img_handle, 255,0,0); $Orange = ImageColorAllocate ($img_handle, 255,105,0); $Yellow = ImageColorAllocate ($img_handle,255,255,0); $Green = ImageColorAllocate ($img_handle, 50,205,50); $Blue = ImageColorAllocate ($img_handle, 105,105,255); $Violet = ImageColorAllocate ($img_handle, 255,105,255); $Grey = ImageColorAllocate ($img_handle, 145,145,145); $White = ImageColorAllocate ($img_handle, 255,255,255); $Silver = ImageColorAllocate ($img_handle, 205,205,205); $Gold = ImageColorAllocate ($img_handle, 205,155,50); $bandColors = array("0" => $Black, "1" => $Brown, "2" => $Red, "3" => $Orange, "4" => $Yellow, "5" => $Green, "6" => $Blue, "7" => $Violet, "8" => $Grey, "9" => $White); $multColors = array("0.01" => $Silver, "0.1" => $Gold, "1" => $Black, "10" => $Brown, "100" => $Red, "1000" => $Orange, "1K" => $Orange, "10K" => $Yellow, "100K" => $Green, "1000K" => $Blue, "1M" => $Blue ); $tolColors = array("20" => $ResColor, "10" => $Silver, "5" => $Gold, "1" => $Brown, "2" => $Red); $coeffColors = array("100" => $Brown, "50" => $Red, "15" => $Orange,"25" => $Yellow); $band01Color = $bandColors[$digit01]; $band02Color = $bandColors[$digit02]; if ($numBands > 4) { $band03Color = $bandColors[$digit03]; } $band04Color = $multColors[$multiplier]; $band05Color = $tolColors[$tolerance]; if ($numBands > 5) { $band06Color = $coeffColors[$tmpCoeff]; } # Fill background with white... imagefilledrectangle($img_handle,0,0,$imageWidth,$imageHeight + $txtHeight,$White); # Draw the resistor ImageRectangleWithRoundedCorners($img_handle, $resX1,$resY1,$resX2,$resY2,$resRad,$ResColor); # Draw the leads imagefilledrectangle($img_handle,0, $leadY, $resX1 ,$leadY + $leadHeight, $Black); imagefilledrectangle($img_handle, $resX2, $leadY, $imageWidth ,$leadY + $leadHeight, $Black); # stripe01 - 1st digit imagefilledrectangle($img_handle, $resStripeX1, $resY1, $resStripeX2, $resY2, $band01Color); # stripe02 - 2nd digit $resStripeX1 = $resStripeX1 + $resStripeInc; $resStripeX2 = $resStripeX2 + $resStripeInc; imagefilledrectangle($img_handle, $resStripeX1, $resY1, $resStripeX2, $resY2, $band02Color); # stripe03 - 3rd digit if ($numBands > 4) { $resStripeX1 = $resStripeX1 + $resStripeInc; $resStripeX2 = $resStripeX2 + $resStripeInc; imagefilledrectangle($img_handle, $resStripeX1, $resY1, $resStripeX2, $resY2, $band03Color); } # stripe04 - multiplier $resStripeX1 = $resStripeX1 + $resStripeInc; $resStripeX2 = $resStripeX2 + $resStripeInc; imagefilledrectangle($img_handle, $resStripeX1, $resY1, $resStripeX2, $resY2, $band04Color); # stripe05 - tolerance $resStripeX1 = $resStripeX1 + $resStripeInc; $resStripeX2 = $resStripeX2 + $resStripeInc; imagefilledrectangle($img_handle, $resStripeX1, $resY1, $resStripeX2, $resY2, $band05Color); # stripe06 - temp coEff if ($numBands > 5) { $resStripeX1 = $resStripeX1 + $resStripeInc; $resStripeX2 = $resStripeX2 + $resStripeInc; imagefilledrectangle($img_handle, $resStripeX1, $resY1, $resStripeX2, $resY2, $band06Color); } # bottom Text imagettftext($img_handle, $font_size, 0 , $textXOffset, ($imageHeight + $txtHeight - 5) , $Black, $dotFont, $outStr); imagepng($img_handle); imagedestroy($img_handle); function ImageRectangleWithRoundedCorners(&$im, $x1, $y1, $x2, $y2, $radius, $color) { // draw rectangle without corners imagefilledrectangle($im, $x1+$radius, $y1, $x2-$radius, $y2, $color); imagefilledrectangle($im, $x1, $y1+$radius, $x2, $y2-$radius, $color); // draw circled corners imagefilledellipse($im, $x1+$radius, $y1+$radius, $radius*2, $radius*2, $color); imagefilledellipse($im, $x2-$radius, $y1+$radius, $radius*2, $radius*2, $color); imagefilledellipse($im, $x1+$radius, $y2-$radius, $radius*2, $radius*2, $color); imagefilledellipse($im, $x2-$radius, $y2-$radius, $radius*2, $radius*2, $color); } ?>