Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Exporting Current Card as .GIF Image

A topic by Salty P. Slug created 12 days ago Views: 90 Replies: 2
Viewing posts 1 to 3
(4 edits) (+3)

I’m making a personality quiz in Decker and am wanting to implement a “Share Your Results” button that takes a screenshot of the current card window, as-is, and save it to a .gif file. Additionally, I would like the file autonamed to the “CardName.gif” if possible.

I tried to research the concept and apply some ideas, but didn’t get any functional results. I dug through the Lil documentation, in addition to the Decker help modules, and couldn’t find anything relevant to what I was trying to accomplish. I’ve been trying so hard to understand the language under the hood in this program, but I still just don’t get it from reading the documentation. I remembered Millie Squilly’s zine template does a similar thing, but I felt the script in that Deck was way too complex for what I’m trying to do. I also tried to analyze the “Export” function in Wigglypaint and struggled to understand how it functions.

I feel like I’ve hit a wall in trying to figure this out. Can anyone help me get something working?

(+2)

In Decker’s list of built-in functions, the last function in the list is:

write[x hint] Open a modal dialog prompting the user to save x.

…with a pointer to additional information lower down. That additional information includes:

image interfaces are written as GIF89a images, and a .gif extension will be appended to any filename without it.

So if we can get an “image interface”, we can let the user save that as a GIF file. Where do image interfaces come from?

Searching the docs for “image interface”, it looks like we can create one from scratch with image[], we can get one by read[]ing a GIF file, you can get images that already exist in a rich-text widget, but none of those are what we want. However, there’s another hit in the App Interface section:

x.render[x] Draw the visual appearance of card or widget x as an Image interface.

…so if we can get an “app interface” from somewhere, we can use it to turn any card or widget into an image interface, which we can pass to write[] to save it as a GIF. A bit earlier in the App Interface docs, it says:

It is available as a global constant named app.

…so we can just say app to refer to the app interface. If a card has a name that’s valid for a Lil variable, then that name is also globally available. If your results card is called, for example, results, then you should be able to save it as a GIF like this:

write[app.render[results]]

Unfortunately, there’s no way to suggest a filename, or where it gets saved. That’s partially for simplicity, but also because Decker can be run in a browser, and browsers are pretty strict about what you’re allowed to do for security reasons.

Developer(+2)

If you just want a static .gif, you can do something like

write[app.render[someCard]]

The app.render[] function takes a card or widget as an argument and produces a screenshot of it as an image interface, and the write[] function prompts the user to save a file; image interfaces are saved as .gif images. Presently, write[] does not allow the script to auto-populate a file name, but it will enforce a ".gif" suffix for whatever name the user chooses when writing out an image. Most of the complexity in the hybrid zine template is related to assembling all the page screenshots into the print layout with variable margins and page aspect ratio.

If you want an animated .gif that e.g. reflects animated patterns and potentially animated contraptions it gets a bit more complicated, but I could help work you through it if you describe your scenario in more detail. The WigglyKit deck includes one example of constructing a dictionary that write[] understands how to make an animated .gif with list of frames and frame delays.