예제 #1
0
파일: Filter.php 프로젝트: JBZoo/Image
 /**
  * Add border to an image
  *
  * @param resource $image  Image GD resource
  * @param array    $params Some
  * @return resource
  * @throws \JBZoo\Utils\Exception
  */
 public static function border($image, array $params = array())
 {
     $params = array_merge(array('color' => '#333', 'size' => 1), $params);
     $size = Helper::range($params['size'], 1, 1000);
     $rgba = Helper::normalizeColor($params['color']);
     $width = imagesx($image);
     $height = imagesy($image);
     $x1 = 0;
     $y1 = 0;
     $x2 = $width - 1;
     $y2 = $height - 1;
     $color = imagecolorallocatealpha($image, $rgba[0], $rgba[1], $rgba[2], $rgba[3]);
     for ($i = 0; $i < $size; $i++) {
         imagerectangle($image, $x1++, $y1++, $x2--, $y2--, $color);
     }
 }
예제 #2
0
파일: Text.php 프로젝트: JBZoo/Image
 /**
  * Determine text color
  *
  * @param mixed        $image GD resource
  * @param string|array $colors
  * @return array
  * @throws Exception
  */
 protected static function _getColor($image, $colors)
 {
     $colors = (array) $colors;
     $result = array();
     foreach ($colors as $color) {
         $rgba = Helper::normalizeColor($color);
         $result[] = imagecolorallocatealpha($image, $rgba[0], $rgba[1], $rgba[2], $rgba[3]);
     }
     return $result;
 }
예제 #3
0
파일: Filter.php 프로젝트: Ruyan/Image
 /**
  * Fill image with color
  *
  * @param mixed  $image     GD resource
  * @param string $color     Hex color string, array(red, green, blue) or array(red, green, blue, alpha).
  *                          Where red, green, blue - integers 0-255, alpha - integer 0-127
  * @return $this
  * @throws Exception
  */
 public static function fill($image, $color = '#000000')
 {
     $width = imagesx($image);
     $height = imagesy($image);
     $rgba = Helper::normalizeColor($color);
     $fillColor = imagecolorallocatealpha($image, $rgba[0], $rgba[1], $rgba[2], $rgba[3]);
     Helper::addAlpha($image, false);
     imagefilledrectangle($image, 0, 0, $width, $height, $fillColor);
 }
예제 #4
0
파일: Image.php 프로젝트: JBZoo/Image
 /**
  * Add filter to current image
  *
  * @param string|callable $filter
  * @return $this
  *
  * @throws Exception
  */
 public function addFilter($filter)
 {
     $args = func_get_args();
     $args[0] = $this->_image;
     $newImage = null;
     if (is_string($filter)) {
         $filterClass = __NAMESPACE__ . '\\Filter';
         if (method_exists($filterClass, $filter)) {
             $newImage = call_user_func_array(array($filterClass, $filter), $args);
         } else {
             throw new Exception('Undefined Image Filter: ' . $filter);
         }
     } elseif (is_callable($filter)) {
         $newImage = call_user_func_array($filter, $args);
     }
     if (Helper::isGdRes($newImage)) {
         $this->_replaceImage($newImage);
     }
     return $this;
 }