If canvas cannot be used, then the only possible solution would be to use AJAX to query the server. On the server there is exactly the same picture as on the client, or the picture is sent to it along with the request. The server finds the color of the pixel in X and Y coordinates from the request, and returns its color in JSON format.
PHP server code:
<?php header("Content-Type: application/json; charset=UTF-8"); $x = $_GET["x"]; $y = $_GET["y"]; //Загрузка JPG-изображения из файла "image.jpg" $image = imagecreatefromjpeg("image.jpg"); //Возвращаем цвет пикселя с координатами ($x, $y) на изображении $image $color = imagecolorat($image, $x, $y); //Получаем составляющие цвета (red, green, blue) $col = new stdClass(); $col->r = ($color >> 16) & 0xFF; $col->g = ($color >> 8) & 0xFF; $col->b = $color & 0xFF; //Выводим JSON для AJAX-запрса: echo json_encode($col); //Освобождаем память сервера imageDestroy($image); ?>
Client code:
<html><body style="margin:0;padding:0"> <img src="image.jpg"><!-- картинка на сервере и клиенте одна --> <br> <div id="mouse-position"></div> <div id="color"></div> <script type="text/javascript"> var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if(this.readyState == 4 && this.status == 200) { var color = JSON.parse(this.responseText); document.getElementById('color').innerHTML = color.r + ', ' + color.g + ', ' + color.b; } }; function sendAJAX(x, y) { xmlhttp.open('GET', 'getColorRGB.php?x='+x+'&y='+y, true); xmlhttp.send(); } document.querySelector('img').onclick = function(e) { document.getElementById('mouse-position').innerHTML = 'x = ' + e.pageX + ', y = ' + e.pageY; sendAJAX(e.pageX, e.pageY) }; </script> </body></html>
Notice that <body style="margin:0;padding:0"> is specified here so that the image is displayed in the upper left corner without an indent. This is done so that the picture is combined with the coordinates of the document, because e.pageX and e.pageY display the coordinates of the document. In general, here it is still necessary to correctly transfer the coordinates, if the picture is shifted. But for this example it is unnecessary.