[ANN] File-to-image

122 views
Skip to first unread message

Martin Eden

unread,
Jan 21, 2026, 3:54:11 PM (5 days ago) Jan 21
to lu...@googlegroups.com
Hello guys,

This evening I wrote simple tool to represent bytes as grayscale pixels.

If someone wants to experiment with it, code is here:

  https://github.com/martin-eden/Lua-BinToImg

It uses spiral filling (and basic turtle class). For image serialization
text PNM format is used. Conversion to PNG is done via third-party tool.

As usually it's self-sufficient repo and all code is written by me.


Did anyone experiment with space-filling curves?

Like Peano's or Hilbert's? I wrote simple spiral on square grid and
quite happy with results. Of course I tried raster (left-to-right,
newline) filling and it's boring.


-- Martin


Denis Dos Santos Silva

unread,
Jan 22, 2026, 9:51:50 AM (4 days ago) Jan 22
to lua-l
awesome!!!

Lars Müller

unread,
Jan 24, 2026, 12:40:38 PM (2 days ago) Jan 24
to lu...@googlegroups.com
Fun fact: PNG is actually a very simple format, especially if you just want to write an ARGB8 file.

I have some related code around: https://github.com/appgurueu/modlib/blob/59ed71df15e4e01e0bb096e7b1d709ea9fdb25cb/minetest/png.lua

This uses some Luanti (formerly Minetest) APIs that wrap zlib to do the (de)compression.
It's pretty short, about ~100 loc for the encoder. There's also a pretty much full-fledged decoder there.
That is a couple more hundred lines, but still not that large.

So what I'm saying is, if it tickles your fancy, directly writing PNGs from Lua is an option.

Or just bindings to libpng. 🙃

- Lars

p.s. alternatively, there's also the "quite okay image format" (QOI, https://qoiformat.org/) that seems to live up to its name and is even simpler than PNG.


--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lua-l+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/lua-l/84351670-be18-4621-bf03-314c36032fe5n%40googlegroups.com.

Martin Eden

unread,
Jan 25, 2026, 10:21:47 AM (23 hours ago) Jan 25
to lu...@googlegroups.com
On 2026-01-24 19:40, 'Lars Müller' via lua-l wrote:
> Fun fact: PNG is actually a very simple format, especially if you just
> want to write an ARGB8 file.
>
> I have some related code around:
> <https://github.com/appgurueu/modlib/blob/59ed71df15e4e01e0bb096e7b1d709ea9fdb25cb/minetest/png.lua>
>
> This uses some Luanti (formerly Minetest) APIs that wrap zlib to do
> the (de)compression.
> It's pretty short, about ~100 loc for the encoder. There's also a
> pretty much full-fledged decoder there.
> That is a couple more hundred lines, but still not that large.
>
> So what I'm saying is, if it tickles your fancy, directly writing PNGs
> from Lua is an option.
>
> Or just bindings to libpng. 🙃
>
> - Lars
>
> p.s. alternatively, there's also the "quite okay image format" (QOI,
> <https://qoiformat.org/>) that seems to live up to its name and is
> even simpler than PNG.
>
Hello Lars,

Thanks for related sources to PNG and QOI. Yeah I know that PNG is not
complex for simple cases. But even in your use case it requires deflate
codec.

I've discovered there is text format that is almost as simple as
possible. Just ASCII tokens:

  P2
  3 2 255
  128 000 64
  092 000 32

So codec for it can be written on-the-fly without reading documentation.
It is supported by stock viewer on my Linux Mint so so far it is best
fit for my mathematical experiments. (Which is basically just
generating and visualizing integer matrices.)

Of course there is no compression, so generated files are not suitable
for storing in collections.

But it amazes me how fast and simple I can do things in Lua
(in comparison with say C or Pascal). For example there to set pixel
I typically have to create record like (x: int, y: int) or
take coordinates as explicit "x" and "y" arguments. In Lua I'm just
passing { 100, 50 } without even bothering to name data and not
thinking about strict types compatibility.

-- Martin

Reply all
Reply to author
Forward
0 new messages