牛牛在线工具

imagegammacorrect()

收录 8868 个 PHP 函数,含用途说明与用法示例。

imagegammacorrect()

对图像进行伽马校正

函数名称:imagegammacorrect() 适用版本:PHP 4 >= 4.0.6, PHP 5, PHP 7 用法:imagegammacorrect() 函数用于对图像进行伽马校正。它可以调整图像的亮度和对比度,以改善图像的显示效果。 语法:bool imagegammacorrect(resource $image, float $inputgamma, float $outputgamma) 参数: $image:图像资源,通过imagecreatefromjpeg()、imagecreatefrompng()等函数创建。 $inputgamma:输入伽马值,范围为0.1到10,值越小表示图像越暗,值越大表示图像越亮。 $outputgamma:输出伽马值,范围为0.1到10,值越小表示图像对比度越高,值越大表示图像对比度越低。 返回值:成功时返回 true,失败时返回 false。 示例: // 创建一个图像资源 $image = imagecreatefromjpeg('image.jpg'); // 对图像进行伽马校正 $inputgamma = 0.5; $outputgamma = 1.5; $result = imagegammacorrect($image, $inputgamma, $outputgamma); if ($result) { // 保存修改后的图像 imagejpeg($image, 'image_corrected.jpg'); echo '图像伽马校正成功!'; } else { echo '图像伽马校正失败!'; } // 释放图像资源 imagedestroy($image); 上述示例中,首先通过imagecreatefromjpeg()函数创建了一个图像资源,然后使用imagegammacorrect()函数对图像进行了伽马校正。通过指定输入伽马值和输出伽马值,可以调整图像的亮度和对比度。最后,使用imagejpeg()函数保存修改后的图像,并释放图像资源。如果图像伽马校正成功,将输出“图像伽马校正成功!”;如果失败,将输出“图像伽马校正失败!”。