/** * Return the fillstyle at positions X, Y * @param int $x The X position * @param int $y The Y position * @param int $w The Width * @param int $h The Height * @return int A GD fillstyle * @access private */ function _getFillStyleAt($x, $y, $w, $h) { $this->_getFillStyle(); if (isset($GLOBALS['_Image_Graph_gd2'])) { ImageCopyResampled($this->_image, $this->_image, $x, $y, $this->_left, $this->_top, $w, $h, $this->width() + 1, $this->height() + 1); } else { ImageCopyResized($this->_image, $this->_image, $x, $y, $this->_left, $this->_top, $w, $h, $this->width() + 1, $this->height() + 1); } ImageSetTile($this->_canvas(), $this->_image); return IMG_COLOR_TILED; }
/** * 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); } }
<?php $im = ImageCreate(200, 100); $black = ImageColorAllocate($im, 0, 0, 0); $im_tile = ImageCreateFromGif(dirname(__FILE__) . "/bug43121.gif"); ImageSetTile($im, $im_tile); ImageFill($im, 0, 0, IMG_COLOR_TILED); ImageDestroy($im); print "OK";