Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

"Import Image..." button

A topic by eoin2 created Apr 12, 2023 Views: 366 Replies: 5
Viewing posts 1 to 3
(+1)

The Ornamented Ovum got me thinking of using Decker to make selfies with protest or campaign messages... it was all the rage about 10 years ago. Twibbon is an example.

Is there a way to trigger "open_file('image/*',load_image)" from a button click, so people can import images into a deck which is protected (i.e. menu hidden)? I find the File > Open Image... option is too fiddly for mobile devices, and I think I'd like to hide the menubar anyway.

Developer (1 edit) (+1)

Yes. Just as it is possible to export images with the "write[]" function, you can import images with "read[]", which takes a few arguments to specify what type of file you wish to open, and how you wish to interpret it. The documentation for this is near the bottom of  the Built-In Functions section of the manual.

As an example, let's say we have a card with a canvas named "c" and a button with a script like so:


The default behavior for importing an image is to posterize it to Decker's 16-color palette. If we want a dithered image, we need to read it in grayscale and resize it (in this case using another image as a scratchpad) before we perform the dithering for best quality:


In these examples I'm resizing the image to fit the dimensions of the canvas, which slightly vertically squishes the image of Pippi the hen. Depending on your specific needs you might also choose to resize the image and/or the canvas proportionally, letterbox or crop the image.

It's also perhaps worth noting that Decker is capable of decoding the individual frames of animated GIF images, so it's possible to make a variety of animation player/viewer applications. The Bazaar has some examples. Likewise, it's also possible to export animated GIFs with "write[]".

Does that give you a useful starting point?

Thank you!

The posterised image works, but I can't get the dithered version to work, and I'm afraid I'm also saving the background behind the canvas for some reason....

See https://wwwdot.org/dither-save-bug.html

Developer

Looks like you have a typo of ':' instead of '.' in your grayscale import script. Try this:

on click do
 # make 1-bit dithered image
 i:read["image" "gray"]
 r:image[c.size]
 r.paste[i 0,0,r.size]
 r.transform["dither"]
 c.paste[r]
end

Sometimes it's helpful to try things step-by-step in the Listener when they don't seem to work properly:

As for image export, you're only copying from the card's background image, which does not include the contents of any canvases stacked on top:

on click do
 write[card.image.copy[c.pos c.size]]
end

If you want to export the image, you need to "copy[]" from the canvas:

on click do
 write[c.copy[]]
end

And as in the examples for The Ornamented Ovum, you may want to map pattern 0 (transparent) to pattern 32 (opaque white) before exporting:

on click do
 write[c.copy[].map[0 dict 32]]
end

(+1)

Ah you're so patient -- thank you!

Here it is now: https://wwwdot.org/1bit-photobooth.html

Mastadon and Facebook appear to be happy with the resulting gif image output, but Twitter complains that the file is invalid.

(+1)

I left it "unprotected" with the menu and listener and so on available for debugging purposes, but I was thinking of making something basically like this, which I'd then iframe into another webpage with some share buttons, so people can click to share/tweet/etc. and optionally make a cool 1-bit protest image to include in their social media post.