zoukankan      html  css  js  c++  java
  • PHP imagecolorclosestalpha

    imagecolorclosestalpha — 取得与指定的颜色加透明度最接近的颜色的索引。高佣联盟 www.cgewang.com

    语法

    int imagecolorclosestalpha ( resource $image , int $red , int $green , int $blue , int $alpha )

    返回图像调色板中与指定的 RGB 值以及 alpha 深度最"接近"的颜色。

    参数

    • image 由图像创建函数(例如 imagecreatetruecolor())返回的图像资源。
    • red 红色成分的值。
    • green 绿色成分的值。
    • blue 蓝色成分的值。
    • alpha 一个介于 0 和 127 之间的值。0 表示完全不透明,127 表示完全透明。

    颜色参数是介于 0 和 255 之间的整数,或者是介于 0x00 和 0xFF 之间的十六进制数。

    返回值

    返回调色板中最接近的颜色的索引。

    实例

    搜索图像中的一组颜色。

    <?php
    // 从一个图像开始,并将其转换为一个基于调色板的图像
    $im = imagecreatefrompng('figures/imagecolorclosest.png');
    imagetruecolortopalette($im, false, 255);
    
    // 搜索颜色 (RGB)
    $colors = array(
        array(254, 145, 154, 50),
        array(153, 145, 188, 127),
        array(153, 90, 145, 0),
        array(255, 137, 92, 84)
    );
    
    // 循环遍历,查找调色板中最接近的颜色
    // 返回搜索次数,搜索的 RGB 和最接近的匹配的 RGB
    foreach($colors as $id => $rgb)
    {
        $result = imagecolorclosestalpha($im, $rgb[0], $rgb[1], $rgb[2], $rgb[3]);
        $result = imagecolorsforindex($im, $result);
        $result = "({$result['red']}, {$result['green']}, {$result['blue']}, {$result['alpha']})";
    
        echo "#$id: 搜索 ($rgb[0], $rgb[1], $rgb[2], $rgb[3]); 最接近的匹配: $result。
    ";
    }
    
    imagedestroy($im);
    ?>

    以上实例的输出类似于:

    #0: 搜索 (254, 145, 154, 50); 最接近的匹配: (252, 150, 148, 0)。
    #1: 搜索 (153, 145, 188, 127); 最接近的匹配: (148, 150, 196, 0)。
    #2: 搜索 (153, 90, 145, 0); 最接近的匹配: (148, 90, 156, 0)。
    #3: 搜索 (255, 137, 92, 84); 最接近的匹配: (252, 150, 92, 0)。
  • 相关阅读:
    H5页面尺寸兼容rem
    Mysql索引、explain执行计划
    mysql物理结构
    mysql 架构
    excel 写
    好的开源项目
    批量插入大量数据
    文件下载回显
    shardingsphere 实现 springboot集成 多数据源
    前后端代码特殊符号乱码问题
  • 原文地址:https://www.cnblogs.com/yc10086/p/13156056.html
Copyright © 2011-2022 走看看