JBZoo\Image\Filter::opacity PHP Method

opacity() public static method

Changes the opacity level of the image
public static opacity ( resource $image, float | integer $opacity ) : mixed
$image resource Image GD resource
$opacity float | integer 0-1 or 0-100
return mixed
    public static function opacity($image, $opacity)
    {
        // Determine opacity
        $opacity = Helper::opacity($opacity);
        $width = imagesx($image);
        $height = imagesy($image);
        $newImage = imagecreatetruecolor($width, $height);
        // Set a White & Transparent Background Color
        $bg = imagecolorallocatealpha($newImage, 0, 0, 0, 127);
        imagefill($newImage, 0, 0, $bg);
        // Copy and merge
        Helper::imageCopyMergeAlpha($newImage, $image, array(0, 0), array(0, 0), array($width, $height), $opacity);
        imagedestroy($image);
        return $newImage;
    }