We are trying to solve How to get intersection point(s) of two glyphs? and there are some interesting subtasks. In word cloud algorithms they are converting glyphs (a vector form) to a raster form and they apply some algorithm (using spiral or other path) to position the glyphs/words/terms.
Are we able to do the same in the TeX world? We can convert resulting PDF file to raster graphics easily (GhostScript, ImageMagick, GraphicsMagick), or, we could use TikZ+externalization library. Well we are not processing them at a pixel level as we are able to do, e.g. in the GD library + PHP scripting language.
I've checked Lua rocks and it doesn't look we have a lot of options there to process bitmapped pictures. The only useful tool seems to be LuaGL, but it looks as a complicated tool. I'm thinking of Python and its packages, but that's a different story if we would like to try calculations on-the-fly.
One more time, I'm sorry I'm not providing MWE. It's likely I'm just searching for a proper Lua library. Lua is used in the game industry, they probably have a lot of useful libraries.
My very last idea is to use JavaScript which can be loaded into the PDF file. I'm not using this approach as I know it's browser-dependent.
For now, after I get a raster graphics I use ImageMagick, I modify the files, and then I'm loading the resulting pictures back at a TeX level.
\clipboxand "operates" on each slice. It is not, to my mind, efficient, and may not even be in the same ballpark with your problem. But I mention it anyhow. – Steven B. Segletes Jul 21 '17 at 19:46