Advertisement
j0h

AvgBS

j0h
Oct 13th, 2014
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.73 KB | None | 0 0
  1. <?php
  2. //The purpose of this script is to help me figure out if I am averaging and translating colors correctly for the ring spectrometer
  3.  
  4. $fiel = "1.png";
  5. list($width, $height, $type, $attr) = getimagesize($fiel);
  6. echo "<img src=\"". $fiel."\" $attr alt=\"getimagesize() example\" />";
  7. $im = imagecreatefrompng("1.png");
  8. $Pi = pi();
  9.  
  10. $centerX = $width / 2;
  11. $centerY = $height / 2;
  12. echo "<br>The picture here is " . $width . " wide, and " . $height . " tall. <br>";
  13. echo "<br>The center of the image is at " .$centerX . ", " . $centerY ;
  14. echo '<br>Test Trig Fucntions php <br> Get all cordinates for a circle<br>';
  15. //$r = 1 ;
  16. $sum = 0;
  17. //echo 'Radiuz == ' . $r . '<br> X, Y, PixelColour at that point.<br><br>';
  18.  
  19. //Max radius
  20. if ($centerX < $centerY){
  21.     $maxRad = $centerX - 1;
  22. }
  23.     elseif
  24.         ($centerY <= $centerX){
  25.         $maxRad = $centerY -1;
  26.     }
  27.          
  28.  
  29.  
  30.  
  31.  
  32. echo "Maximumux Radius is: " . $maxRad  . "<br><br>Ring Number, Average Value:<br>";
  33.  
  34. for($r=1; $r<=$maxRad; $r++ ){
  35.     for ($a=0; $a<=360; $a++) {
  36.  
  37.        $ax =  $r*cos($a*$Pi/180) + $centerX ; //x
  38.        $ay =  $r*sin($a*$Pi/180) + $centerY ; //y
  39.        $PXCol = imagecolorat($im, $ax, $ay); //outputs a decimal number for color
  40. //     echo $ax . ", " . $ay . ", " . $PXCol . "<br>";
  41.             $sum = $sum + $PXCol;
  42.             $avg = $sum / 360;
  43.             $trunc = round($avg);
  44.         }
  45.         echo  $r . ", " . dechex($trunc) . "<br>";
  46. }  
  47.  
  48. // choose a color for the ellipse
  49. $ellipseColor = imagecolorallocate($im, 0, 0, 255);
  50.  
  51. // draw the white ellipse
  52. imagefilledellipse($im, $centerX, $centerY, 300, 300, $ellipseColor);
  53.  
  54. // Output the image.
  55. //header("Content-type: image/png");
  56. //imagepng($im);
  57. //echo "<br>Trucated Average:  ".$trunc."<br>";
  58. //echo "<br>Average in Hex:  ". dechex($trunc) ."<br>";
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement