title: Viewing transparent image and deciding where does the opacity starts and ends on X and Y coordinates
body: <p>I have PNG image that is has a lot of white space that must be there. Let's say the image is 1000 by 1000 pixels and it has a black square 100 by 100 pixels located at 450px by 450px which is exactly in the center (the black square could be anywhere on the transparent image).</p>
  
  <p>Now, is there a way to load the big image (the 1000x1000 pixel one) and search to find the X and Y position of the black square that is in the middle?</p>
  
  <p>This should be cross browser compatible or at lest the major browser compatible.</p>
  
  <p>The example on here: <a href="http://jsfiddle.net/cwolves/GaEeG/2/" rel="nofollow">http://jsfiddle.net/cwolves/GaEeG/2/</a> shows how to see if the mouse is over the transparent part of an image. The problem is that I'm not sure how to scan with the code to get where transparency opacity starts from X and Y side of the image. It also seems to work only on Chrome.</p>
  
  <pre><code>var imgData,
       width = 200,
      height = 200;
  
  $('#mask').bind('mousemove', function(ev){
      if(!imgData){ initCanvas(); }
      var imgPos = $(this).offset(),
        mousePos = {x : ev.pageX - imgPos.left, y : ev.pageY - imgPos.top},
        pixelPos = 4*(mousePos.x + height*mousePos.y),
           alpha = imgData.data[pixelPos+3];
  
      $('#opacity').text('Opacity = ' + ((100*alpha/255) &lt;&lt; 0) + '%');
  });
  
  function initCanvas(){
      var canvas = $('&lt;canvas width="'+width+'" height="'+height+'" /&gt;')[0],
             ctx = canvas.getContext('2d');
  
      ctx.drawImage($('#mask')[0], 0, 0);
      imgData = ctx.getImageData(0, 0, width, height);
  }
  </code></pre>
  
  <p>I can only use PHP or JavaScript/plugins to do this.</p>
  
  <p>I hope there's a way to do this. Thanks.</p>