• imagecolorat 图片某点的颜色值




    读取图片某个点的颜色值

    $res = imagecreatefrompng(...);
    $rgba = imagecolorat($res, 0, 0); // 获取图片坐标为x=>0, y=>0的点的颜色值,如果图片有问题的话,可能返回false或0

    // 解析颜色和透明度
    $r = ($rgba >> 16) & 0xFF;
    $g = ($rgba >> 8) & 0xFF;
    $b = $rgba & 0xFF;
    $alpha = (($rgba >> 24) & 0x7F);

    // 可以使用imagecolorsforindex 获取具体颜色
    $arr_rgba = imagecolorsforindex($res, $rgba); // 具体的颜色

    print_r($arr_rgba); // 会返回颜色值数组
    Array
    (
        [red] => 255
        [green] => 255
        [blue] => 255
        [alpha] => 0
    )

    imagecolorat函数,返回【基于调色板(palette based image,即ps里的图片模式为索引图片的图片)或真彩色(true color image)】图片在图片某坐标的颜色值

    imagecreatefromjpeg 创建真彩色图片, imagecreatefromgif 创建基于调色板的图片,而imagecreatefrompng 创建基于调色板或者真彩色图片,具体依据png图片所使用的图片格式

  • 相关阅读:
    自我介绍 Self Introduction
    HDU1864 最大报销额
    HDU2955 Robberies
    Sicily 1509. Rails
    Sicily 1031. Campus
    Sicily 1090. Highways
    Sicily 1034. Forest
    Sicily 1800. Sequence
    Sicily 1150. 简单魔板
    CodeVS4919 线段树练习4
  • 原文地址:https://www.cnblogs.com/lbnnbs/p/14927546.html
Copyright © 2020-2023  润新知