Page 1 of 1

Export Layered Image as .png? (solved)

Posted: Tue Jul 10, 2018 7:31 pm
by noeinan
Hey! I am working on a character generator and I was wondering if there is a way to export a layered image as a .png using the current view of said image. (Like, if there are multiple poses and facial expressions, you can click a button and export that specific view as a picture file.)

Re: Export Layered Image as .png?

Posted: Tue Jul 10, 2018 8:12 pm
by trooper6
Not that I know of. However, since you have all the layers, you could just assemble the image you want in GIMP and export to png there.

Re: Export Layered Image as .png?

Posted: Tue Jul 10, 2018 9:32 pm
by noeinan
Hm, that's unfortunate. I can definitely make the .png on my own, since I have the layers (I use paint.net) but I was hoping for an in-game way of doing it quickly without all the copy/paste and merging.

Re: Export Layered Image as .png?

Posted: Tue Jul 10, 2018 10:55 pm
by Imperf3kt
You could use the screenshot function to capture the whole screen. Then you'd need to supply a mask for players so they can remove the background and add an alpha layer in an image editor.

I wonder if the screenshot function can capture layers instead of the whole screen.

Re: Export Layered Image as .png?

Posted: Wed Jul 11, 2018 3:27 am
by noeinan
Oh, that's an interesting idea! I didn't know that Ren'Py had a screenshot function, could you show me an example of how that code works? (Or a link, if there's documentation on it?)

For my generator, I luckily wouldn't need to remove the background, since it is just plain white. But it would be super helpful if I could have the game crop the image to just one frame before exporting the screenshot. I wonder if something like that would be possible...

Re: Export Layered Image as .png?

Posted: Wed Jul 11, 2018 6:34 am
by Imperf3kt
Ren'Py can take screenshots by default with the s key on your keyboard. I think the printscreen button also works, but can't actually confirm that.

Anyway, assuming you want this as a function of your game instead (say, for instance, a "capture" button), you could probably use renpy.screenshot or screenshot. Probably easiest if you use the second one, as you can call it as an action of a button. The first link is more specialised and for advanced use.
So, to use it, I assume you can do something like this:

Code: Select all

screen myscreen():
    textbutton _("Take photo") action Screenshot
    
label start:
    show screen myscreen
    "Take a photo!"
    "Go on, click the button."
    hide screen myscreen
    return
To crop the image to a certain area, you can use config.screenshot_crop. I suspect this will crop ALL screenshots to this area (potentially including save game screenshots), so may require further research to make it separate from regular screenshots.

I haven't personally used either of these functions, so I cannot particularly help much further, but I'm more than willing to give things a go myself if you get stuck. (Time provided)

Re: Export Layered Image as .png?

Posted: Wed Jul 11, 2018 5:25 pm
by noeinan
Thank you! I actually don't mind if it crops all screenshots to that area, since the generator will only display images there anyhow. This is great and I will have to test it out!

[Edit] I got it working! Thanks so much for your help!

I added this to the top of my script file:

Code: Select all

define config.screenshot_crop = (0.0, 0.0, 463, 970)
And this textbutton to my screen:

Code: Select all

textbutton _("Save") action Screenshot() xalign 0.99 yalign 0.95
Now I just need to figure out how to have user inputed save locations.