Esempio n. 1
0
 /**
  * Get the GD applicable fillstyle
  *
  * @param mixed $fillStyle The fillstyle to return, false if the one
  *   explicitly set
  * @return mixed A GD compatible fillstyle
  * @access private
  */
 function _getFillStyle($fillStyle = false, $x0 = 0, $y0 = 0, $x1 = 0, $y1 = 0)
 {
     if ($this->_tileImage != null) {
         ImageDestroy($this->_tileImage);
         $this->_tileImage = null;
     }
     if ($fillStyle == 'transparent') {
         return false;
     } elseif ($fillStyle === false) {
         if (is_resource($this->_fillStyle)) {
             $x = min($x0, $x1);
             $y = min($y0, $y1);
             $w = abs($x1 - $x0) + 1;
             $h = abs($y1 - $y0) + 1;
             if ($this->_gd2) {
                 $this->_tileImage = ImageCreateTrueColor($this->getWidth(), $this->getHeight());
                 ImageCopyResampled($this->_tileImage, $this->_fillStyle, $x, $y, 0, 0, $w, $h, ImageSX($this->_fillStyle), ImageSY($this->_fillStyle));
             } else {
                 $this->_tileImage = ImageCreate($this->getWidth(), $this->getHeight());
                 ImageCopyResized($this->_tileImage, $this->_fillStyle, $x, $y, 0, 0, $w, $h, ImageSX($this->_fillStyle), ImageSY($this->_fillStyle));
             }
             ImageSetTile($this->_canvas, $this->_tileImage);
             return IMG_COLOR_TILED;
         } elseif (is_array($this->_fillStyle) && isset($this->_fillStyle['direction'])) {
             $width = abs($x1 - $x0) + 1;
             $height = abs($y1 - $y0) + 1;
             switch ($this->_fillStyle['direction']) {
                 case 'horizontal':
                     $count = $width;
                     break;
                 case 'vertical':
                     $count = $height;
                     break;
                 case 'horizontal_mirror':
                     $count = $width / 2;
                     break;
                 case 'vertical_mirror':
                     $count = $height / 2;
                     break;
                 case 'diagonal_tl_br':
                 case 'diagonal_bl_tr':
                     $count = sqrt($width * $width + $height * $height);
                     break;
                 case 'radial':
                     $count = max($width, $height, sqrt($width * $width + $height * $height)) + 1;
                     break;
             }
             $count = round($count);
             if ($this->_gd2) {
                 $this->_tileImage = ImageCreateTrueColor($this->getWidth(), $this->getHeight());
             } else {
                 $this->_tileImage = ImageCreate($this->getWidth(), $this->getHeight());
             }
             $startColor = Image_Canvas_Color::color2RGB($this->_fillStyle['direction'] == 'radial' ? $this->_fillStyle['end'] : $this->_fillStyle['start']);
             $endColor = Image_Canvas_Color::color2RGB($this->_fillStyle['direction'] == 'radial' ? $this->_fillStyle['start'] : $this->_fillStyle['end']);
             $redIncrement = ($endColor[0] - $startColor[0]) / $count;
             $greenIncrement = ($endColor[1] - $startColor[1]) / $count;
             $blueIncrement = ($endColor[2] - $startColor[2]) / $count;
             $color = false;
             for ($i = 0; $i < $count; $i++) {
                 unset($color);
                 if ($i == 0) {
                     $color = $startColor;
                     unset($color[3]);
                 } else {
                     $color[0] = round($redIncrement * $i + $redIncrement + $startColor[0]);
                     $color[1] = round($greenIncrement * $i + $greenIncrement + $startColor[1]);
                     $color[2] = round($blueIncrement * $i + $blueIncrement + $startColor[2]);
                 }
                 $color = Image_Canvas_Color::allocateColor($this->_tileImage, $color);
                 switch ($this->_fillStyle['direction']) {
                     case 'horizontal':
                         ImageLine($this->_tileImage, $x0 + $i, $y0, $x0 + $i, $y1, $color);
                         break;
                     case 'vertical':
                         ImageLine($this->_tileImage, $x0, $y1 - $i, $x1, $y1 - $i, $color);
                         break;
                     case 'horizontal_mirror':
                         if ($x0 + $i <= $x1 - $i) {
                             ImageLine($this->_tileImage, $x0 + $i, $y0, $x0 + $i, $y1, $color);
                             ImageLine($this->_tileImage, $x1 - $i, $y0, $x1 - $i, $y1, $color);
                         }
                         break;
                     case 'vertical_mirror':
                         if ($y0 + $i <= $y1 - $i) {
                             ImageLine($this->_tileImage, $x0, $y0 + $i, $x1, $y0 + $i, $color);
                             ImageLine($this->_tileImage, $x0, $y1 - $i, $x1, $y1 - $i, $color);
                         }
                         break;
                     case 'diagonal_tl_br':
                         if ($i > $width && $i > $height) {
                             $polygon = array($x1, $y0 + $i - $width - 1, $x1, $y1, $x0 + $i - $height - 1, $y1);
                         } elseif ($i > $width) {
                             $polygon = array($x0, $y0 + $i, $x0, $y1, $x1, $y1, $x1, $y0 + $i - $width - 1);
                         } elseif ($i > $height) {
                             $polygon = array($x0 + $i - $height - 1, $y1, $x1, $y1, $x1, $y0, $x0 + $i, $y0);
                         } else {
                             $polygon = array($x0, $y0 + $i, $x0, $y1, $x1, $y1, $x1, $y0, $x0 + $i, $y0);
                         }
                         ImageFilledPolygon($this->_tileImage, $polygon, count($polygon) / 2, $color);
                         break;
                     case 'diagonal_bl_tr':
                         if ($i > $width && $i > $height) {
                             $polygon = array($x1, $y1 - $i + $width - 1, $x1, $y0, $x0 + $i - $height - 1, $y0);
                         } elseif ($i > $width) {
                             $polygon = array($x0, $y1 - $i, $x0, $y0, $x1, $y0, $x1, $y1 - $i + $width - 1);
                         } elseif ($i > $height) {
                             $polygon = array($x0 + $i - $height - 1, $y0, $x1, $y0, $x1, $y1, $x0 + $i, $y1);
                         } else {
                             $polygon = array($x0, $y1 - $i, $x0, $y0, $x1, $y0, $x1, $y1, $x0 + $i, $y1);
                         }
                         ImageFilledPolygon($this->_tileImage, $polygon, count($polygon) / 2, $color);
                         break;
                     case 'radial':
                         if ($this->_gd2 && $i < $count) {
                             ImageFilledEllipse($this->_tileImage, $x0 + $width / 2, $y0 + $height / 2, $count - $i, $count - $i, $color);
                         }
                         break;
                 }
             }
             ImageSetTile($this->_canvas, $this->_tileImage);
             return IMG_COLOR_TILED;
         } else {
             return $this->_color($this->_fillStyle);
         }
     } else {
         return $this->_color($fillStyle);
     }
 }
Esempio n. 2
0
 /**
  * Get the color index for the RGB color
  *
  * @param int $color The color
  * @return int The GD image index of the color
  * @access private
  */
 function _color($color = false)
 {
     if ($color === false || $color === 'opague' || $color === 'transparent') {
         return false;
     } else {
         $color = Image_Canvas_Color::color2RGB($color);
         $color[0] = $color[0] / 255;
         $color[1] = $color[1] / 255;
         $color[2] = $color[2] / 255;
         return $color;
     }
 }
Esempio n. 3
0
 /**
  * Internal method to correctly set the colors.
  *
  * @param mixed $col1 color 1
  * @param mixed $col2 color 2
  *
  * @return void
  * @access   private
  */
 function _setColors($col1, $col2)
 {
     $this->color1 = Image_Canvas_Color::color2RGB($col1);
     $this->color2 = Image_Canvas_Color::color2RGB($col2);
 }
Esempio n. 4
0
 /**
  * Get the opacity for the RGB color
  *
  * @param int $color The color
  * @return int A SVG compatible opacity value
  * @access private
  */
 function _opacity($color = false)
 {
     if ($color === false) {
         return false;
     } else {
         $color = Image_Canvas_Color::color2RGB($color);
         if ($color[3] != 255) {
             return sprintf('%0.1f', $color[3] / 255);
         } else {
             return false;
         }
     }
 }
Esempio n. 5
0
 /**
  * Get the color index for the RGB color
  *
  * @param int $color The color
  * @return int The GD image index of the color
  * @access private
  */
 function _color($color = false)
 {
     if ($color === false) {
         return false;
     } else {
         $color = Image_Canvas_Color::color2RGB($color);
         $color[0] = $color[0] / 255;
         $color[1] = $color[1] / 255;
         $color[2] = $color[2] / 255;
         return $color;
     }
 }