News for hackers. Stuff that matters.
Re:Compressing Text into Images by cb_ru on Sunday January 14, 2024 @01:46PM (#38993164)
This technique has been pretty popular among the demoscene community, where the size of the programs are often restricted to 4K or less. The PNG compression (ie DEFLATE compression) has been used as a way to compress the source code of javascript demos, in order to reduce the final code size. There are several "packers" that can convert javascript source files into self-executing PNG+HTML files, such as JsExe: https://www.pouet.net/prod.php?which=59298
Re:Compressing Text into Images by crazygringo on Sunday January 14, 2024 @01:51PM (#38993211)
Oh wow, so that's basically a way of getting around the fact that JavaScript doesn't have built-in zip/gz/deflate support, but browsers do have built-in PNG support? Clever.
Re:Compressing Text into Images by oritsnile on Sunday January 14, 2024 @04:41PM (#38994711)
There is the Compression Streams API which hast gzip and deflate support, but it pretty new. Firefox supports it since halfe a year.

https://developer.mozilla.org/en-US/docs/Web/API/Compression...

Re:Compressing Text into Images by lifthrasiir on Sunday January 14, 2024 @11:19PM (#38997415)
Unfortunately it still doesn't expose Brotli [1], which should be already in web browsers due to `Content-Encoding: br`. There is a very roundabout way to decompress a Brotli stream though, and that's how I've got a typing game into 1 KB of JavaScript [2] back in 2022.

[1] https://github.com/WICG/compression/issues/34

[2] https://js1024.fun/demos/2022/18/readme

Re:Compressing Text into Images by lifthrasiir on Sunday January 14, 2024 @08:57PM (#38996557)
And if you use the same technique to WebP Lossless, which is generally better than PNG for most cases, you will find that it hardly improves the compression. This is to be expected because underlying algorithms are same for both, but WebP uses a slightly more tweaked algorithm to exploit more patterns in 2D images. A code and in general text is not a 2D image, so there is nothing left to exploit.