JBZoo\Utils\Image::opacity2Alpha PHP Method

opacity2Alpha() public static method

Convert opacity value to alpha
public static opacity2Alpha ( integer $opacity ) : integer
$opacity integer
return integer
    public static function opacity2Alpha($opacity)
    {
        $opacity = self::opacity($opacity);
        $opacity /= 100;
        $aplha = 127 - 127 * $opacity;
        $aplha = self::alpha($aplha);
        return $aplha;
    }

Usage Example

Beispiel #1
0
 /**
  * Set colorize
  *
  * @param resource  $image      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
  * @param float|int $opacity    0-100
  * @return $this
  *
  * @throws \JBZoo\Utils\Exception
  */
 public static function colorize($image, $color, $opacity)
 {
     $rgba = Helper::normalizeColor($color);
     $alpha = Helper::opacity2Alpha($opacity);
     $red = Helper::color($rgba[0]);
     $green = Helper::color($rgba[1]);
     $blue = Helper::color($rgba[2]);
     imagefilter($image, IMG_FILTER_COLORIZE, $red, $green, $blue, $alpha);
 }