本文詳細介紹瞭如何使用像素顏色創建動態圖像映射,並為傳統圖像映射提供了快速,靈活的替代方案。該方法避免了固定尺寸區域的局限性並允許任何形狀或大小。
關鍵優勢:
它的工作原理:
Database: Store the hex color codes and their corresponding country URLs. jQuery:
jquery(document).ready(function($){$('#theworldmapimage')。on('click' - = 5;如果(鼠標> 500){鼠標= 13; y =“鼠標); $ y = $ _request ['y']; $ im = imagecreatefrompng($域。“/images/worldmap-coloured.png”); $ rgb = imageColorat($ im,$ x,$ y); $ r =($ rgb>> 16)& 0xff; $ g =($ rgb>> 8)& 0xff; $ b = $ rgb& 0xff;功能RGB2HTML($ r,$ g = -1,$ b = -1){// ...(函數保持不變)...} $ hex = rgb2html($ r,$ r,$ g,$ b); $ debug =(“ r”。$ r。“ g”。$ g。“ b”。$ b。“ hex =#”。$ hex); $ html =“”; $ qry =“從``shex_colour =''''select ofert country。$ hex。 if(mysqli_query($ conn,$ qry)){//使用mysqli代替不棄用的mysql $ result = mysqli_query($ conn,$ conn,$ qry); while($ row = mysqli_fetch_assoc($ result)){$ country_filename = converttofileName($ row ['country']); $ html = $ domain。“/”。$ country_filename。“/”; $ debug。=“”。 $ country_filename; }} mysqli_close($ conn); //關閉MySQLI連接迴聲$ html; }?>
注意: PHP代碼已更新以使用 mysqli
進行數據庫交互,替換了已棄用的 mysql
函數。確保您建立了數據庫連接( $ conn
)。
See a demo (Click on the “Show world map” to show the dynamic image map, then click on any country).
This approach offers benefits for responsive design, SEO (through alt text and title attributes), and performance optimization (caching and image compression). FAQ部分提供了有關錯誤處理和優化技術的更多詳細信息。
以上是基於像素顏色的動態圖像圖的詳細內容。更多資訊請關注PHP中文網其他相關文章!