Example #1
0
 /**
  * Set clipping to occur
  * 
  * Parameter array:
  * 
  * 'x0': int X point of Upper-left corner
  * 'y0': int X point of Upper-left corner
  * 'x1': int X point of lower-right corner
  * 'y1': int Y point of lower-right corner
  */
 function setClipping($params = false)
 {
     if ($params === false) {
         $index = count($this->_clipping) - 1;
         if (isset($this->_clipping[$index])) {
             $params = $this->_clipping[$index];
             $canvas = $params['canvas'];
             ImageCopy($canvas, $this->_canvas, min($params['x0'], $params['x1']), min($params['y0'], $params['y1']), min($params['x0'], $params['x1']), min($params['y0'], $params['y1']), abs($params['x1'] - $params['x0'] + 1), abs($params['y1'] - $params['y0'] + 1));
             $this->_canvas = $canvas;
             unset($this->_clipping[$index]);
         }
     } else {
         $params['canvas'] = $this->_canvas;
         if ($this->_gd2) {
             $this->_canvas = ImageCreateTrueColor($this->_width, $this->_height);
             if ($this->_alpha) {
                 ImageAlphaBlending($this->_canvas, true);
             }
         } else {
             $this->_canvas = ImageCreate($this->_width, $this->_height);
         }
         if ($this->_gd2 && $this->_antialias === 'native') {
             ImageAntialias($this->_canvas, true);
         }
         ImageCopy($this->_canvas, $params['canvas'], 0, 0, 0, 0, $this->_width, $this->_height);
         $this->_clipping[count($this->_clipping)] = $params;
     }
 }
Example #2
0
 /**
  * Create the GD canvas.
  *
  * Parameters available:
  *
  * 'width' The width of the graph on the canvas
  *
  * 'height' The height of the graph on the canvas
  *
  * 'left' The left offset of the graph on the canvas
  *
  * 'top' The top offset of the graph on the canvas
  * 
  * 'antialias' = 'native' enables native GD antialiasing - this
  * method has no severe impact on performance (approx +5%). Requires PHP
  * 4.3.2 (with bundled GD2)
  * 
  * 'antialias' = {true|'driver'} Image_Graph implemented method. This method
  * has a severe impact on performance, drawing an antialiased line this
  * way is about XX times slower, with an overall performance impact of
  * about +40%. The justification for this method is that if native support
  * is not available this can be used, it is also a future feature that this
  * method for antialiasing will support line styles.
  * 
  * Use antialiased for best results with a line/area chart having just a few
  * datapoints. Native antialiasing does not provide a good appearance with
  * short lines, as for example with smoothed charts. Antialiasing does not
  * (currently) work with linestyles, neither native nor driver method!
  * 
  * 'noalpha' = true If alpha blending is to be disabled
  *
  * 'filename' An image to open, on which the graph is created on
  *
  * 'gd' A GD resource to add the image to, use this option to continue
  * working on an already existing GD resource. Make sure this is passed 'by-
  * reference' (using &)
  * 
  * 'usemap' Initialize an image map
  *
  * 'gd' and 'filename' are mutually exclusive with 'gd' as preference
  *
  * 'width' and 'height' are required unless 'filename' or 'gd' are
  * specified, in which case the width and height are taken as the actual
  * image width/height. If the latter is the case and 'left' and/or 'top' was
  * also specified, the actual 'width'/'height' are altered so that the graph
  * fits inside the canvas (i.e 'height' = actual height - top, etc.)
  *
  * @param array $param Parameter array
  */
 function Image_Canvas_GD($param)
 {
     include_once 'Image/Canvas/Color.php';
     parent::Image_Canvas_WithMap($param);
     $this->_gd2 = $this->_version() == 2;
     $this->_font = array('font' => 1, 'color' => 'black');
     if (isset($param['gd']) && is_resource($param['gd'])) {
         $this->_canvas =& $param['gd'];
     } elseif (isset($param['filename'])) {
         $this->_canvas =& $this->_getGD($param['filename']);
     } else {
         if ($this->_gd2) {
             $this->_canvas = ImageCreateTrueColor($this->_width, $this->_height);
             if (!isset($param['noalpha']) || $param['noalpha'] !== true) {
                 ImageAlphaBlending($this->_canvas, true);
             }
         } else {
             $this->_canvas = ImageCreate($this->_width, $this->_height);
         }
     }
     if (isset($param['antialias'])) {
         $this->_antialias = $param['antialias'];
     }
     if ($this->_antialias === true) {
         $this->_antialias = 'driver';
     }
     if ($this->_gd2 && $this->_antialias === 'native') {
         ImageAntialias($this->_canvas, true);
     }
 }