0
我不確定這是否可能,但我試圖取$ css_color的值並將其設置爲div中的十六進制值。還有$ x和$ y值。抓取PHP信息並放入div內
本質上,我試圖從圖像中獲取$ x $ y信息和十六進制代碼值,並將其匹配到格式化的顏色值數組中,然後將格式爲「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?>是更安全的賭注。短標籤是不好建議.. http://stackoverflow.com/questions/200640/are-php-short-tags-acceptable-to-use – rlemon