php 手册中有如下说明: imagecolorat (PHP 4, PHP 5) imagecolorat Get the index of the color of a pixel ?php $im = imagecreatefrompng ( php.png ); $rgb = imagecolorat ( $im , 10 , 15 ); $r = ( $rgb 16 ) 0xFF ; $g = ( $rgb 8 ) 0xFF ; $b = $rg
php 手册中有如下说明:
imagecolorat
(PHP 4, PHP 5)
imagecolorat — Get the index of the color of a pixel
立即学习“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 );
?>
于是可以写一个专门的处理函数:
function getImageMainColor($strUrl) {
$imageInfo = getimagesize($strUrl);
//图片类型
$imgType = strtolower(substr(image_type_to_extension($imageInfo[2]), 1));
//对应函数
$imageFun = ‘imagecreatefrom’ . ($imgType == ‘jpg’ ? ‘jpeg’ : $imgType);
$i = $imageFun($strUrl);
MDWechat是一款xposed插件,能够使使微信Material Design化。功能实现的功能有:1.主界面 TabLayout Material 化,支持自定义图标2.主界面 4 个页面背景修改3.全局 ActionBar 和 状态栏 颜色修改,支持主界面和聊天页面的沉浸主题(4.0新增)4.自动识别微信深色模式以调整MDwechat配色方案(3.6新增)5.主界面添加悬浮按钮(Float
1
//循环色值
$rColorNum=$gColorNum=$bColorNum=$total=0;
for ($x=0;$x for ($y=0;$y $rgb = imagecolorat($i,$x,$y); //三通道 $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> $b = $rgb & 0xFF; $rColorNum += $r; $gColorNum += $g; $bColorNum += $b; $total++; } } $rgb = array(); $rgb['r'] = round($rColorNum/$total); $rgb['g'] = round($gColorNum/$total); $rgb['b'] = round($bColorNum/$total); return $rgb; }
原文地址:php如何识别图片的主颜色, 感谢原作者分享。
& 0xFF;
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号