Grafika\Gd\Editor::gdAlpha PHP Method

gdAlpha() public static method

Convert alpha value of 0 - 1 to GD compatible alpha value of 0 - 127 where 0 is opaque and 127 is transparent
public static gdAlpha ( float $alpha ) : integer
$alpha float Alpha value of 0 - 1. Example: 0, 0.60, 0.9, 1
return integer
    public static function gdAlpha($alpha)
    {
        $scale = round(127 * $alpha);
        return $invert = 127 - $scale;
    }

Usage Example

Beispiel #1
0
 /**
  * TODO: Anti-aliased curves
  * @param ImageInterface $image
  * @return ImageInterface
  */
 public function draw($image)
 {
     list($x, $y) = $this->pos;
     $left = $x + $this->width / 2;
     $top = $y + $this->height / 2;
     if (null !== $this->fillColor) {
         list($r, $g, $b, $alpha) = $this->fillColor->getRgba();
         $fillColorResource = imagecolorallocatealpha($image->getCore(), $r, $g, $b, Editor::gdAlpha($alpha));
         imagefilledellipse($image->getCore(), $left, $top, $this->width, $this->height, $fillColorResource);
     }
     // Create borders. It will be placed on top of the filled ellipse (if present)
     if (0 < $this->getBorderSize() and null !== $this->borderColor) {
         // With border > 0 AND borderColor !== null
         list($r, $g, $b, $alpha) = $this->borderColor->getRgba();
         $borderColorResource = imagecolorallocatealpha($image->getCore(), $r, $g, $b, Editor::gdAlpha($alpha));
         imageellipse($image->getCore(), $left, $top, $this->width, $this->height, $borderColorResource);
     }
     return $image;
 }
All Usage Examples Of Grafika\Gd\Editor::gdAlpha