1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-22 13:32:56 +02:00

added fill method

This commit is contained in:
Oliver Vogel
2013-01-30 13:22:31 +01:00
parent 141ac6c2b2
commit 564da1b939

View File

@@ -283,6 +283,43 @@ class Image
return $this;
}
/**
* Fill image with given hexadecimal color at position x,y
*
* @param string $color
* @param integer $pos_x
* @param integer $pos_y
* @return Image
*/
public function fill($color, $pos_x = 0, $pos_y = 0)
{
imagefill($this->resource, $pos_x, $pos_y, $this->getColor($color));
return $this;
}
/**
* Set single pixel
*
* @param string $color
* @param integer $pos_x
* @param integer $pos_y
* @return Image
*/
public function pixel($color, $pos_x = 0, $pos_y = 0)
{
imagesetpixel($this->resource, $pos_x, $pos_y, $this->getColor($color));
return $this;
}
public function text($text, $pos_x = 0, $pos_y = 0, $size = 16, $color = '000000', $fontfile = null, $angle = 0)
{
$fontfile = is_null($fontfile) ? 'public/ttf/bebas/BEBAS___.TTF' : $fontfile;
imagettftext($this->resource, $size, $angle, $pos_x, $pos_y, $this->getColor($color), $fontfile, $text);
// imagestring($this->resource, 5, $pos_x, $pos_y, $text, $color);
return $this;
}
/**
* Pixelate current image
*
@@ -361,6 +398,27 @@ class Image
return $data;
}
/**
* Allocate color from given string
*
* @param string $value
* @return int
*/
private function getColor($hexcolor)
{
// $args = func_get_args();
$value = (string) $value;
$color = array(
'r' => '0x' . substr($value, 0, 2),
'g' => '0x' . substr($value, 2, 2),
'b' => '0x' . substr($value, 4, 2)
);
return imagecolorallocate($this->resource, $color['r'], $color['g'], $color['b']);
}
/**
* Save image in filesystem
*