• PHP获取图片颜色值


    PHP获取图片颜色值,检测图片主要颜色的代码:

    <?php
    $i=imagecreatefromjpeg("photo3.jpg");//测试图片,自己定义一个,注意路径
    for ($x=0;$x<imagesx($i);$x++) {
        for ($y=0;$y<imagesy($i);$y++) {
            $rgb = imagecolorat($i,$x,$y);
            $r=($rgb >>16) & 0xFF;
            $g=($rgb >> & 0xFF;
            $b=$rgb & 0xFF;
            $rTotal += $r;
            $gTotal += $g;
            $bTotal += $b;
            $total++;
        }
    }
    $rAverage = round($rTotal/$total);
    $gAverage = round($gTotal/$total);
    $bAverage = round($bTotal/$total);
    //示例:
    echo $rAverage;
    ?>
  • 相关阅读:
    LeetCode "Sum Root to Leaf Numbers"
    LeetCode "Single Number"
    POJ #1033
    POJ #1011
    POJ #2411
    POJ #1276
    POJ #1260
    POJ #1221
    POJ #1080
    POJ #1050
  • 原文地址:https://www.cnblogs.com/qingsong/p/5932046.html
Copyright © 2020-2023  润新知