Hacker News new | ask | show | jobs
by fragmede 5775 days ago
Idle thought - would it be possible using layers to do selectable text in an image - top layer is 100% transparent text, 2nd layer is the image. The font face is preserved (though it still won't wrap), but the text is still selectable for copy and paste.
3 comments

Browsers are "smart"- they won't let you select text that's 100% transparent. 99% transparency works... but also looks kind of weird if the texts don't overlap perfectly.

You can roll your own text selection in javascript (on top of the bitmap) if you know the glyph positions though- that's what e.g. Google Books does. It's a valid option if you don't care about zoomability.

Are you sure? I just made a quick test and it works ok in FF, Opera, Chrome, Safari, IE9 (Windows 7, Ubuntu 9.10):

  <body style="background:url(image.png)">
   <span style="color:rgba(0,0,0,0)">Hello world</span>
  </body>
That's almost what Google Docs PDF viewer does. Each page is a JPG. This is served to the user with a catalogue of text layout then JavaScript is used to simulate selection and copying.
Yep, you can do just that. Browsers that support rgba for text color make it quite easy and in older browsers you can do onselect tricks and the like to make it work.