TeeChartPHP
[ class tree: TeeChartPHP ] [ index: TeeChartPHP ] [ all elements ]

Source for file Gradient.php

Documentation is available at Gradient.php

  1. <?php
  2.  
  3.  /**
  4.  * Gradient class
  5.  *
  6.  * Description:
  7.  *
  8.  * @author
  9.  * @copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
  10.  * @version 1.0
  11.  * @package TeeChartPHP
  12.  * @subpackage drawing
  13.  * @link http://www.steema.com
  14.  */
  15.  
  16. class Gradient extends TeeBase {
  17.  
  18.     private $width 0;
  19.     private $height 0;
  20.     private $direction 0// Vertical
  21.     private $startColor// ='#f00';
  22.     private $endColor//='#000';
  23.     private $step=0;  // = intval(abs($step));
  24.     private $customTargetPolygon null;
  25.  
  26.     // properties from teechart
  27.     protected $visible=false;
  28.  
  29.     //private Color startColor = Color.GOLD;
  30.     //private Color middleColor = Color.GRAY;
  31.     //private Color endColor = Color.WHITE;
  32.  
  33.     //private float sigmaFocus = 0.5F;
  34.     //private float sigmaScale = 1.0F;
  35.     //private boolean sigma;
  36.     //private boolean wrapTile = false;
  37.     //private boolean gammaCorrection;
  38.  
  39.     //private boolean useMiddle;
  40.     //private int transparency = 0;
  41.     //private double angle = 0D;
  42.  
  43.     //private int radialX = 0;
  44.     //private int radialY = 0;
  45.  
  46.     // Interceptors
  47.     
  48.     function __get$property {
  49.       $method ="get{$property}";
  50.       if method_exists$this$method ) ) {
  51.         return $this->$method();
  52.       }
  53.     }
  54.  
  55.     function __set $property,$value {
  56.       $method ="set{$property}";
  57.       if method_exists$this$method ) ) {
  58.         return $this->$method($value);
  59.       }
  60.     }
  61.  
  62.     function Gradient($c=null{
  63.         $this->direction GradientDirection::$VERTICAL;
  64.         $this->startColor new Color(255,100,100);
  65.         $this->endColor new Color(255,255,255);
  66.  
  67. /* TODO remove        $this->startColor = '#bbb'; //new Color(255,100,100);
  68.         $this->endColor = '#fff'; // new Color(255,255,255);
  69.         $this->step = intval(abs(0));
  70.         */
  71.  
  72.         parent::__construct($c);
  73.     }
  74.  
  75.     /**
  76.      * Copies the Gradient parameter properties into the Canvas.Gradient object.
  77.      *
  78.      * @param value Gradient
  79.      */
  80.     public function assign($value{
  81.         //angle = value.angle;
  82.         $this->direction $value->direction;
  83.         $this->startColor $value->startColor;
  84.         //middleColor = value.middleColor;
  85.         $this->endColor $value->endColor;
  86.         //radialX = value.radialX;
  87.         //radialY = value.radialY;
  88.  
  89.         $this->customTargetPolygon $value->customTargetPolygon;
  90.         /*
  91.         sigmaFocus = value.sigmaFocus;
  92.         sigmaScale = value.sigmaScale;
  93.         sigma = value.sigma;
  94.         wrapTile = value.wrapTile;
  95.         gammaCorrection = value.gammaCorrection;
  96.         */
  97.  
  98.         //useMiddle = value.useMiddle;
  99.         $this->visible = $value->visible;
  100.         //transparency = value.transparency;
  101.     }
  102.  
  103.  
  104.     /*
  105.       Script Name: GD Gradient Fill
  106.       Script URI: http://planetozh.com/blog/my-projects/images-php-gd-gradient-fill/
  107.       Description: Creates a gradient fill of any shape (rectangle, ellipse, vertical, horizontal, diamond)
  108.       Author: Ozh
  109.       Version: 1.1
  110.       Author URI: http://planetozh.com/
  111.     */
  112.     /*
  113.     *  Parameters :
  114.     *  - width and height : integers, dimesions of your image.
  115.     *  - direction : string, shape of the gradient.
  116.     *    Can be : vertical, horizontal, rectangle (or square), ellipse, ellipse2, circle, circle2, diamond.
  117.     *  - startcolor : string, start color in 3 or 6 digits hexadecimal.
  118.     *  - endcolor : string, end color in 3 or 6 digits hexadecimal.
  119.     *  - step : integer, optional, default to 0. Step that breaks the smooth blending effect.
  120.     *
  121.     *  @return resource
  122.     *  Example :
  123.     *  $image = new Gradient(300,200,'ellipse','#f00','#000',0);
  124.     */
  125.     function gradientFill($w,$h,$d,$s,$e,$step=0{
  126.  
  127.         $this->width $w;
  128.         $this->height $h;
  129.         $this->direction $d;
  130.         $this->startcolor $s;
  131.         $this->endcolor $e;
  132.         $this->step intval(abs($step));
  133.  
  134.         // Attempt to create a blank image in true colors, or a new palette based image if this fails
  135.         if (function_exists('imagecreatetruecolor')) {
  136.             $this->image imagecreatetruecolor($this->width,$this->height);
  137.         elseif (function_exists('imagecreate')) {
  138.             $this->image imagecreate($this->width,$this->height);
  139.         else {
  140.             die('Unable to create an image');
  141.         }
  142.  
  143.         // Fill it
  144.         $this->fill($this->image,$this->direction,$this->startcolor,$this->endcolor);
  145.  
  146.         // Show it
  147.         $this->display($this->image);
  148.  
  149.         // Return it
  150.         return $this->image;
  151.     }
  152.  
  153.  
  154.     // Displays the image with a portable function that works with any file type
  155.     // depending on your server software configuration
  156.     function display ($im{
  157.         if (function_exists("imagepng")) {
  158.             header("Content-type: image/png");
  159.             imagepng($im);
  160.         }
  161.         elseif (function_exists("imagegif")) {
  162.             header("Content-type: image/gif");
  163.             imagegif($im);
  164.         }
  165.         elseif (function_exists("imagejpeg")) {
  166.             header("Content-type: image/jpeg");
  167.             imagejpeg($im""0.5);
  168.         }
  169.         elseif (function_exists("imagewbmp")) {
  170.             header("Content-type: image/vnd.wap.wbmp");
  171.             imagewbmp($im);
  172.         else {
  173.             die("Doh ! No graphical functions on this server ?");
  174.         }
  175.         return true;
  176.     }
  177.  
  178.     // The main function that draws the gradient
  179.     function fill($im,$direction=null,$start=null,$end=null{
  180.  
  181.         (int)$r=0;
  182.         (int)$g=0;
  183.         (int)$b=0;
  184.  
  185.         if ($direction==null$direction=$this->direction;
  186.         if ($start==null$start=$this->startColor;
  187.         if ($end==null$end=$this->endColor;
  188.  
  189.         switch($direction{
  190.             case GradientDirection::$HORIZONTAL:
  191.                 $line_numbers imagesx($im);
  192.                 $line_width imagesy($im);
  193.                 list($r1,$g1,$b1$this->rgbtoArray($start);
  194.                 list($r2,$g2,$b2$this->rgbtoArray($end);
  195.                 break;
  196.             case GradientDirection::$VERTICAL:
  197.                 $line_numbers imagesy($im);
  198.                 $line_width imagesx($im);
  199.                 list($r1,$g1,$b1$this->rgbtoArray($start);
  200.                 list($r2,$g2,$b2$this->rgbtoArray($end);
  201.                 break;
  202.             case GradientDirection::$ELLIPSE:
  203.                 $width imagesx($im);
  204.                 $height imagesy($im);
  205.                 $rh=$height>$width?1:$width/$height;
  206.                 $rw=$width>$height?1:$height/$width;
  207.                 $line_numbers min($width,$height);
  208.                 $center_x $width/2;
  209.                 $center_y $height/2;
  210.                 list($r1,$g1,$b1$this->rgbtoArray($end);
  211.                 list($r2,$g2,$b2$this->rgbtoArray($start);
  212.                 break;
  213.             case GradientDirection::$ELLIPSE2:
  214.                 $width imagesx($im);
  215.                 $height imagesy($im);
  216.                 $rh=$height>$width?1:$width/$height;
  217.                 $rw=$width>$height?1:$height/$width;
  218.                 $line_numbers sqrt(pow($width,2)+pow($height,2));
  219.                 $center_x $width/2;
  220.                 $center_y $height/2;
  221.                 list($r1,$g1,$b1$this->rgbtoArray($end);
  222.                 list($r2,$g2,$b2$this->rgbtoArray($start);
  223.                 break;
  224.             case GradientDirection::$CIRCLE:
  225.                 $width imagesx($im);
  226.                 $height imagesy($im);
  227.                 $line_numbers sqrt(pow($width,2)+pow($height,2));
  228.                 $center_x $width/2;
  229.                 $center_y $height/2;
  230.                 $rh $rw 1;
  231.                 list($r1,$g1,$b1$this->rgbtoArray($end);
  232.                 list($r2,$g2,$b2$this->rgbtoArray($start);
  233.                 break;
  234.             case GradientDirection::$CIRCLE2:
  235.                 $width imagesx($im);
  236.                 $height imagesy($im);
  237.                 $line_numbers min($width,$height);
  238.                 $center_x $width/2;
  239.                 $center_y $height/2;
  240.                 $rh $rw 1;
  241.                 list($r1,$g1,$b1$this->rgbtoArray($end);
  242.                 list($r2,$g2,$b2$this->rgbtoArray($start);
  243.                 imagefill($im00imagecolorallocate$im$r1$g1$b1 ));
  244.                 break;
  245.             case GradientDirection::$SQUARE:
  246.             case GradientDirection::$RECTANGLE:
  247.                 $width imagesx($im);
  248.                 $height imagesy($im);
  249.                 $line_numbers max($width,$height)/2;
  250.                 list($r1,$g1,$b1$this->rgbtoArray($end);
  251.                 list($r2,$g2,$b2$this->rgbtoArray($start);
  252.                 break;
  253.             case GradientDirection::$DIAMOND:
  254.                 list($r1,$g1,$b1$this->rgbtoArray($end);
  255.                 list($r2,$g2,$b2$this->rgbtoArray($start);
  256.                 $width imagesx($im);
  257.                 $height imagesy($im);
  258.                 $rh=$height>$width?1:$width/$height;
  259.                 $rw=$width>$height?1:$height/$width;
  260.                 $line_numbers min($width,$height);
  261.                 break;
  262.             default:
  263.         }
  264.  
  265.         for $i 0$i $line_numbers$i=$i+1+$this->step {
  266.             // old values :
  267.             $old_r=$r;
  268.             $old_g=$g;
  269.             $old_b=$b;
  270.             // new values :
  271.             $r $r2 $r1 != intval$r1 $r2 $r1 $i $line_numbers ) )$r1;
  272.             $g $g2 $g1 != intval$g1 $g2 $g1 $i $line_numbers ) )$g1;
  273.             $b $b2 $b1 != intval$b1 $b2 $b1 $i $line_numbers ) )$b1;
  274.             // if new values are really new ones, allocate a new color, otherwise reuse previous color.
  275.             // There's a "feature" in imagecolorallocate that makes this function
  276.             // always returns '-1' after 255 colors have been allocated in an image that was created with
  277.             // imagecreate (everything works fine with imagecreatetruecolor)
  278. //review todo            if ( "$old_r,$old_g,$old_b" != "$r,$g,$b")
  279.                 $fill imagecolorallocate$im$r$g$b );
  280.             switch($direction{
  281.                 case GradientDirection::$VERTICAL:                
  282.                     imagefilledrectangle($im0$i$line_width$i+$this->step$fill);
  283.                     break;
  284.                 case GradientDirection::$HORIZONTAL:
  285.                     imagefilledrectangle$im$i0$i+$this->step$line_width$fill );
  286.                     break;
  287.                 case GradientDirection::$ELLIPSE:
  288.                 case GradientDirection::$ELLIPSE2:
  289.                 case GradientDirection::$CIRCLE:
  290.                 case GradientDirection::$CIRCLE2:
  291.                     imagefilledellipse ($im,$center_x$center_y($line_numbers-$i)*$rh($line_numbers-$i)*$rw,$fill);
  292.                     break;
  293.                 case GradientDirection::$SQUARE:
  294.                 case GradientDirection::$RECTANGLE:
  295.                     imagefilledrectangle ($im,$i*$width/$height,$i*$height/$width,$width-($i*$width/$height)$height-($i*$height/$width),$fill);
  296.                     break;
  297.                 case GradientDirection::$DIAMOND:
  298.                     imagefilledpolygon($imarray (
  299.                         $width/2$i*$rw-0.5*$height,
  300.                         $i*$rh-0.5*$width$height/2,
  301.                         $width/2,1.5*$height-$i*$rw,
  302.                         1.5*$width-$i*$rh$height/)4$fill);
  303.                     break;
  304.                 default:
  305.             }
  306.         }
  307.     }
  308.  
  309.  
  310.     function fillGradient($im,$x,$y,$w,$h,$direction=null,$start=null,$end=null{
  311.  
  312.         (int)$r=0;
  313.         (int)$g=0;
  314.         (int)$b=0;
  315.  
  316.         if ($direction==null$direction=$this->direction;
  317.         if ($start==null$start=$this->startColor;
  318.         if ($end==null$end=$this->endColor;
  319.  
  320.         switch($direction{
  321.             case GradientDirection::$HORIZONTAL:
  322.                 $line_numbers =  $w// imagesx($im);
  323.                 $line_width $h//  imagesy($im);
  324.                 list($r1,$g1,$b1$this->rgbtoArray($start);
  325.                 list($r2,$g2,$b2$this->rgbtoArray($end);
  326.                 break;
  327.             case GradientDirection::$VERTICAL:
  328.                 $line_numbers $h// imagesy($im);
  329.                 $line_width $w// imagesx($im);
  330.                 list($r1,$g1,$b1$this->rgbtoArray($start);
  331.                 list($r2,$g2,$b2$this->rgbtoArray($end);
  332.                 break;
  333.             case GradientDirection::$ELLIPSE:
  334.                 $width $w// imagesx($im);
  335.                 $height $h// imagesy($im);
  336.                 $rh=$height>$width?1:$width/$height;
  337.                 $rw=$width>$height?1:$height/$width;
  338.                 $line_numbers min($width,$height);
  339.                 $center_x $width/2;
  340.                 $center_y $height/2;
  341.                 list($r1,$g1,$b1$this->rgbtoArray($end);
  342.                 list($r2,$g2,$b2$this->rgbtoArray($start);
  343.                 break;
  344.             case GradientDirection::$ELLIPSE2:
  345.                 $width $w//imagesx($im);
  346.                 $height $h// imagesy($im);
  347.                 $rh=$height>$width?1:$width/$height;
  348.                 $rw=$width>$height?1:$height/$width;
  349.                 $line_numbers sqrt(pow($width,2)+pow($height,2));
  350.                 $center_x $width/2;
  351.                 $center_y $height/2;
  352.                 list($r1,$g1,$b1$this->rgbtoArray($end);
  353.                 list($r2,$g2,$b2$this->rgbtoArray($start);
  354.                 break;
  355.             case GradientDirection::$CIRCLE:
  356.                 $width $w//imagesx($im);
  357.                 $height $h// imagesy($im);
  358.                 $line_numbers sqrt(pow($width,2)+pow($height,2));
  359.                 $center_x $width/2;
  360.                 $center_y $height/2;
  361.                 $rh $rw 1;
  362.                 list($r1,$g1,$b1$this->rgbtoArray($end);
  363.                 list($r2,$g2,$b2$this->rgbtoArray($start);
  364.                 break;
  365.             case GradientDirection::$CIRCLE2:
  366.                 $width $w// imagesx($im);
  367.                 $height $h// imagesy($im);
  368.                 $line_numbers min($width,$height);
  369.                 $center_x $width/2;
  370.                 $center_y $height/2;
  371.                 $rh $rw 1;
  372.                 list($r1,$g1,$b1$this->rgbtoArray($end);
  373.                 list($r2,$g2,$b2$this->rgbtoArray($start);
  374.                 imagefill($im00imagecolorallocate$im$r1$g1$b1 ));
  375.                 break;
  376.             case GradientDirection::$SQUARE:
  377.             case GradientDirection::$RECTANGLE:
  378.                 $width $w// imagesx($im);
  379.                 $height $h// imagesy($im);
  380.                 $line_numbers max($width,$height)/2;
  381.                 list($r1,$g1,$b1$this->rgbtoArray($end);
  382.                 list($r2,$g2,$b2$this->rgbtoArray($start);
  383.                 break;
  384.             case GradientDirection::$DIAMOND:
  385.                 list($r1,$g1,$b1$this->rgbtoArray($end);
  386.                 list($r2,$g2,$b2$this->rgbtoArray($start);
  387.                 $width $w//imagesx($im);
  388.                 $height $h//imagesy($im);
  389.                 $rh=$height>$width?1:$width/$height;
  390.                 $rw=$width>$height?1:$height/$width;
  391.                 $line_numbers min($width,$height);
  392.                 break;
  393.             default:
  394.         }
  395.  
  396.         for $i 0$i $line_numbers$i=$i+1+$this->step {
  397.             // old values :
  398.             $old_r=$r;
  399.             $old_g=$g;
  400.             $old_b=$b;
  401.             // new values :
  402.             $r $r2 $r1 != intval$r1 $r2 $r1 $i $line_numbers ) )$r1;
  403.             $g $g2 $g1 != intval$g1 $g2 $g1 $i $line_numbers ) )$g1;
  404.             $b $b2 $b1 != intval$b1 $b2 $b1 $i $line_numbers ) )$b1;
  405.             // if new values are really new ones, allocate a new color, otherwise reuse previous color.
  406.             // There's a "feature" in imagecolorallocate that makes this function
  407.             // always returns '-1' after 255 colors have been allocated in an image that was created with
  408.             // imagecreate (everything works fine with imagecreatetruecolor)
  409. //review todo            if ( "$old_r,$old_g,$old_b" != "$r,$g,$b")
  410.                 $fill imagecolorallocate$im$r$g$b );
  411.             switch($direction{
  412.                 case GradientDirection::$VERTICAL:                
  413.                     imagefilledrectangle($im0$i$line_width$i+$this->step$fill);
  414.                     break;
  415.                 case GradientDirection::$HORIZONTAL:
  416.                     imagefilledrectangle$im$i0$i+$this->step$line_width$fill );
  417.                     break;
  418.                 case GradientDirection::$ELLIPSE:
  419.                 case GradientDirection::$ELLIPSE2:
  420.                 case GradientDirection::$CIRCLE:
  421.                 case GradientDirection::$CIRCLE2:
  422.                     imagefilledellipse ($im,$center_x$center_y($line_numbers-$i)*$rh($line_numbers-$i)*$rw,$fill);
  423.                     break;
  424.                 case GradientDirection::$SQUARE:
  425.                 case GradientDirection::$RECTANGLE:
  426.                     imagefilledrectangle ($im,$i*$width/$height,$i*$height/$width,$width-($i*$width/$height)$height-($i*$height/$width),$fill);
  427.                     break;
  428.                 case GradientDirection::$DIAMOND:
  429.                     imagefilledpolygon($imarray (
  430.                         $width/2$i*$rw-0.5*$height,
  431.                         $i*$rh-0.5*$width$height/2,
  432.                         $width/2,1.5*$height-$i*$rw,
  433.                         1.5*$width-$i*$rh$height/)4$fill);
  434.                     break;
  435.                 default:
  436.             }
  437.         }
  438.     }
  439.     
  440.     function rgbtoArray($color{
  441.         return Array($color->red,$color->green,$color->blue)
  442.     }
  443.     
  444.     // #ff00ff -> array(255,0,255) or #f0f -> array(255,0,255)
  445.     function hex2rgb($color{
  446.         $color str_replace('#','',$color);
  447.         $s strlen($color3;
  448.         $rgb[]=hexdec(str_repeat(substr($color,0,$s),2/$s));
  449.         $rgb[]=hexdec(str_repeat(substr($color,$s,$s),2/$s));
  450.         $rgb[]=hexdec(str_repeat(substr($color,2*$s,$s),2/$s));
  451.         return $rgb;
  452.     }
  453.  
  454.     /**
  455.      * Determines whether the gradient fill appears on screen.<br>
  456.      * Default value: false
  457.      *
  458.      * @return boolean 
  459.      */
  460.     public function getVisible({
  461.         return $this->visible;
  462.     }
  463.  
  464.     /**
  465.      * Determines whether the gradient fill appears on screen.<br>
  466.      * Default value: false
  467.      *
  468.      * @param value boolean
  469.      */
  470.     public function setVisible($value{
  471.         $this->visible = $this->setBooleanProperty($this->visible$value);
  472.     }
  473.  
  474.     /**
  475.      * Determines the gradient direction
  476.      * Default value: vertical
  477.      *
  478.      * @return string 
  479.      */
  480.     public function getDirection({
  481.         return $this->direction;
  482.     }
  483.  
  484.     /**
  485.      * Determines the gradient direction
  486.      * Default value: vertical
  487.      *
  488.      * @param value string
  489.      */
  490.     public function setDirection($value{
  491.         $this->direction $this->setStringProperty($this->direction$value);
  492.     }
  493.  
  494.  
  495.     /**
  496.      * Determines the gradient startColor
  497.      * Default value:
  498.      *
  499.      * @return string 
  500.      */
  501.     public function getStartColor({
  502.         return $this->startColor;
  503.     }
  504.  
  505.     /**
  506.      * Determines the gradient startColor as RGB
  507.      * Default value:
  508.      *
  509.      * @return Color 
  510.      */
  511.     public function getStartRGBColor({
  512.         //return Utils::hex2rgb($this->startColor);
  513.         return $this->startColor;
  514.     }
  515.     
  516.     /**
  517.      * Determines the gradient startColor
  518.      * Default value:
  519.      *
  520.      * @param value string
  521.      */
  522.     public function setStartColor($value{
  523.         $this->startColor $this->setStringProperty($this->startColor$value);
  524.     }
  525.  
  526.     /**
  527.      * Determines the gradient startColor as RGB
  528.      * Default value:
  529.      *
  530.      * @param value Color
  531.      */
  532.     public function setStartRGBColor($value{
  533. //        $this->startColor = Utils::rgbhex($value->getRed(),$value->getGreen(),$value->getBlue());
  534.         $this->startColor $value;
  535.     }
  536.     
  537.     /**
  538.      * Determines the gradient endColor
  539.      * Default value:
  540.      *
  541.      * @return string 
  542.      */
  543.     public function getEndColor({
  544.         return $this->endColor;
  545.     }
  546.  
  547.     /**
  548.      * 
  549.      * Determines the gradient endColor as RGB
  550.      * Default value:
  551.      *
  552.      * @return Color 
  553.      */
  554.     public function getEndRGBColor({
  555.         return Utils::hex2rgb($this->endColor);        
  556.     }
  557.  
  558.     /**
  559.      * Determines the gradient endColor
  560.      * Default value:
  561.      *
  562.      * @param value string
  563.      */
  564.     public function setEndColor($value{
  565.         $this->endColor $this->setStringProperty($this->endColor$value);
  566.     }
  567.     
  568.     /**
  569.      * Determines the gradient endColor  as RGB
  570.      * Default value:
  571.      *
  572.      * @param value Color
  573.      */
  574.     public function setEndRGBColor($value{
  575.         $this->endColor Utils::rgbhex($value->getRed(),$value->getGreen(),$value->getBlue());        
  576.     }
  577.    
  578.     /// <summary>
  579.     /// Assign a rectangle to this property to define a custom rectangle to a Gradient.
  580.     /// ret Point[]
  581.     /// </summary>
  582.     public function getCustomTargetPolygon()
  583.     {
  584.       return $this->customTargetPolygon;
  585.     }
  586.  
  587.     public function setCustomTargetPolygon($value)
  588.     {
  589.       $this->customTargetPolygon $value;
  590.     }
  591.     
  592.  /*   function imagecolorgradient($img,$x1,$y1,$height,$width,$colA,$colB) {
  593.         
  594.         $varC1=($colA[1]-$colB[1])/$height;
  595.         $varC2=($colA[2]-$colB[2])/$height;
  596.         $varC3=($colA[3]-$colB[3])/$height;
  597.         
  598.         for ($i=0;$i<=$height;$i++) {
  599.           $col=ImageColorAllocate($img,
  600.                $colA[1]-floor($i*$varC1),
  601.                $colA[2]-floor($i*$varC2),
  602.                $colA[3]-floor($i*$varC3));
  603.           ImageLine($img,$x1,$y1+$i,$x1+$width,$y1+$i,$col);
  604.         }
  605.     }    
  606.    */ 
  607.  
  608.    static function imagecolorgradient($img,$x1,$y1,$x2,$y2,$f_c,$s_c){
  609.     
  610.      if($y2>$y1$y=$y2-$y1;
  611.         else $y=$y1-$y2;
  612.      if($f_c[0]>$s_c[0]$r_range=$f_c[0]-$s_c[0];
  613.         else $r_range=$s_c[0]-$f_c[0];
  614.      if($f_c[1]>$s_c[1]$g_range=$f_c[1]-$s_c[1];
  615.         else $g_range=$s_c[1]-$f_c[1];
  616.      if($f_c[2]>$s_c[2]$b_range=$f_c[2]-$s_c[2];
  617.         else $b_range=$s_c[2]-$f_c[2];
  618.      if ($y<>0)
  619.      {
  620.         $r_px=$r_range/$y;
  621.         $g_px=$g_range/$y;
  622.         $b_px=$b_range/$y;
  623.      }
  624.      $r=$f_c[0];
  625.      $g=$f_c[1];
  626.      $b=$f_c[2];
  627.      for($i=0;$i<=$y;$i++){
  628.        $col=imagecolorallocate($img,round($r),round($g),round($b));
  629.        imageline($img,$x1,$y1+$i,$x2,$y1+$i,$col);
  630.        if($f_c[0]<$s_c[0]$r+=$r_px;
  631.        else $r-=$r_px;
  632.        if($f_c[1]<$s_c[1]$g+=$g_px;
  633.        else $g-=$g_px;
  634.        if($f_c[2]<$s_c[2]$b+=$b_px;
  635.        else $b-=$b_px;
  636.      }
  637.      
  638.      return $img;
  639.    }    
  640.    
  641.    
  642.     /**
  643.     *Draws a gradient color filled polygon
  644.     *@access private
  645.     *@return void 
  646.     *@param $ColorHandler 
  647.     */
  648.     private function draw_GradientPolygon($ColorHandler{
  649.         $ProperVertices=array();    
  650.         $CurrentColor=0;
  651.         
  652.         for ($vertex=0;$vertex<count($this->Vertices);$vertex++{
  653.             $Vertex=explode(",",$this->Vertices[$vertex]);
  654.             array_push($ProperVertices,$Vertex[0]);
  655.             array_push($ProperVertices,$Vertex[1]);
  656.         }
  657.             
  658.         for ($i=0;$i<count($ProperVertices)-6;$i+=2{
  659.             
  660.             $current=$i;
  661.             
  662.             $StartPointX=$ProperVertices[$i];
  663.             $StartPointY=$ProperVertices[$i+1];
  664.             $FinishPointX=$ProperVertices[$i+2];
  665.             $FinishPointY=$ProperVertices[$i+3];
  666.         
  667.             $RangeX=$FinishPointX-$StartPointX;
  668.             if ($RangeX==0$RangeX=1;
  669.             
  670.             $Ratio=($FinishPointY-$StartPointY)/$RangeX;
  671.             
  672.             $YPos=$ProperVertices[count($ProperVertices)-1];
  673.             
  674.             for ($XPos=$StartPointX;$XPos<$FinishPointX;$XPos++)
  675.                 ImageLine($this->Canvas,$XPos,$StartPointY+$Ratio*($XPos-$StartPointX),$XPos,$YPos,$ColorHandler[$CurrentColor++]);
  676.         }
  677.         
  678.         $this->draw_Caption();    
  679.     }   
  680. }
  681. ?>

Documentation generated on Wed, 16 Jun 2010 12:05:34 +0200 by phpDocumentor 1.4.1