PHP - imagecolorat() 到 rgb 或 hex?

标签 php css indexing hex rgb

我使用这段代码:

for($x=0;$x<$stageWidth;$x++){
    $stageColors[$x] = [];
    for($y=0;$y<$stageHeight;$y++){
        array_push($stageColors[$x],imagecolorat($pngImage,$x,$y));
    }
}

将所有颜色索引存储在一个数组中。

但是我怎样才能把它们作为 CSS 兼容的东西来回应呢?

例如:

<div style="background:#<?php echo $either_RGBA_OR_HEX; ?>" ></div>

RGBA(或 RGB)或 HEX 并不重要

最佳答案

这是获取 rgb 值的帮助:

<?php
$im = imagecreatefrompng("php.png");
$rgb = imagecolorat($im, 10, 15);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;

var_dump($r, $g, $b);//shows the individual values that you can use
?> 

关于PHP - imagecolorat() 到 rgb 或 hex?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31222703/

相关文章:

php - Magento : getAttributeText doesn't work

PHP Sendmail 发送的电子邮件内容在包含 CSS 内联样式时不显示

html - 无法使用双向绑定(bind)以正确格式显示数据

elasticsearch - ElasticSearch创建具有动态属性的索引

arrays - 排序并保留 n 维数组的索引 -- MATLAB

php - 生成具有不规则步长的范围。优化

PHP 不向 mysql 表提交值

javascript - 全页搜索时模糊背景

html - 更改 WordPress 页面/帖子标记

带有 where 子句和 group by 的 SQL max() 函数不能有效地使用索引