Quick script for stacking images into an .ora

What is it?

When you have some images and you just want to throw them together as layers in an ora file, one of the easiest ways is to hit “open as layers” in the gimp image program and then export to .ora. But if you do this a lot you might want a fast command line program to do this, and that’s what ora_stack is.

It’s nothing very polished, it’s just something I threw together tonight, but it’s a start.

Getting it and installing it

It’s made in Chicken Scheme which means it’s a bit of a hassle to compile and run if you don’t usually use it. But it’s what it is.

Using it

For example, type

in your shell. I’m probably going to call this from shell scripts and aliases if there are some common images or templates I like to stick in there.

Walking through the source code

Just some libraries we use. I love srfi-42 and tend to use it for everything kinda gratuitously, even when a simple for-each or map would do the trick.

Then we parse the calling command line:

Then some guard clauses. This version doesn’t check if the input filenames refer to real image files, let alone make sure they’re png:s. But it does attempt to try to avoid clobbering what you’ve got. If you do want clobbering (maybe you update your images often), just remove the clause and recompile.

I’ll set the frame according to the first (top) layer. While mypaint, gimp and krita can all change the frame size easily enough, it’s even easier to reorder layers, so a tip is to make sure the layer you want to match the frame size is top layer, i.e. first filename on the command line.

Then I’ll define a convenience function to get the new paths for the image layers.

Here is where I create a working directory for the ora’s contents, and add a stack file to it.

Adding #t to create-directory creates the parents so I can create the /data subdir along with creating the working directory.

I’ll just comment on a couple of excerpts from that larger block of code:

Unquote-splicing a null list looks like a weird hack, but it’s a useful pattern for when you conditionally want to include something in a list. I sometimes quasiquote just so I can do this.

This means that each layer will be left-justified and top-justified. mypaint, gimp and krita all have easy tools for moving the layers where you want them. If you change this, remember to unquote:

OK, now we’re done with creating directory and the stack file, the rest is just pretty much Chicken’s equivalent of shell script basics. file-link looks weird but the posix unit doesn’t really have a “copy-file” as far as I know. But it saves on disk space and then the link is deleted as the corresponding image data is zipped up into the .ora file.

guard clauses

Proxied content from gemini://idiomdrottning.org/ora_stack (external content)

Gemini request details:

Original URL
gemini://idiomdrottning.org/ora_stack
Status code
Success
Meta
text/gemini; lang=en
Proxied by
kineto

Be advised that no attempt was made to verify the remote SSL certificate.