我不确定这是否可能,但我试图采取$css_color的值并将其设置为div中的十六进制值。也与$x和$y值。
基本上,我试图从图像中获取$x$y信息和十六进制代码值,并将其与formatted_colors.js中的颜色值数组匹配,然后重建"图像"作为div,背景颜色作为测试。
我的formatted_colors.js数组var colors = []; colors["000000"] = "black"; colors["100000"] = "black";
的例子
下面是一个片段:
<script type="text/javascript" src="jquery-1.6.2.js"></script>
<script src="formatted_colors.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
//iterate through pixels and match rounded color to array in formatted_colors.js
<div class="rounded_color" hex="<?php $css_color ?>" xy="<?php $x.$y ?>"</div>
<div id="<?php $x.$y ?>"></div>
$(document).ready(function() {
$(".rounded_color").each(function(){
var google_color = getColor($(this).attr("hex"));
$('#'+$(this).attr("id")).html(google_color);
$('#'+$(this).attr("id")).css('background-color:', google_color);
})
// get name of color function from formatted_colors.js
function getColor(target_color){
if (colors[target_color] == undefined) { // not found
return "no match";
} else {
return colors[target_color];
}
} // end getColor function
)} // end ready function
</script>
这里是我的全部代码:http://pastebin.com/A4tMsn2C
尝试用<?php echo $x.$y ?>
代替(其他块也类似)。或者,如果你有短标签启用<?= $x . $y ?>
。您的版本只是简单地进行串联并抛出结果。你需要回显你在PHP块内所做的任何事情的结果。