addAlpha() public static method

Add alpha chanel to image resource
public static addAlpha ( mixed $image, boolean $isBlend = true )
$image mixed Image GD resource
$isBlend boolean Add alpha blending
Beispiel #1
0
 /**
  * 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
  * @throws \JBZoo\Utils\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);
 }
Beispiel #2
0
 /**
  * Crop an image
  *
  * @param int $left   Left
  * @param int $top    Top
  * @param int $right  Right
  * @param int $bottom Bottom
  *
  * @return $this
  */
 public function crop($left, $top, $right, $bottom)
 {
     $left = VarFilter::int($left);
     $top = VarFilter::int($top);
     $right = VarFilter::int($right);
     $bottom = VarFilter::int($bottom);
     // Determine crop size
     if ($right < $left) {
         list($left, $right) = array($right, $left);
     }
     if ($bottom < $top) {
         list($top, $bottom) = array($bottom, $top);
     }
     $cropedW = $right - $left;
     $cropedH = $bottom - $top;
     // Perform crop
     $newImage = imagecreatetruecolor($cropedW, $cropedH);
     Helper::addAlpha($newImage);
     imagecopyresampled($newImage, $this->_image, 0, 0, $left, $top, $cropedW, $cropedH, $cropedW, $cropedH);
     // Update meta data
     $this->_replaceImage($newImage);
     $this->_width = $cropedW;
     $this->_height = $cropedH;
     return $this;
 }