Export Layered Image as .png? (solved)

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Export Layered Image as .png? (solved)

#1 Post 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.)
Last edited by noeinan on Thu Jul 12, 2018 3:29 am, edited 1 time in total.
Image

Image
Image

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Export Layered Image as .png?

#2 Post 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.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Export Layered Image as .png?

#3 Post 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.
Image

Image
Image

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Export Layered Image as .png?

#4 Post 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.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Export Layered Image as .png?

#5 Post 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...
Image

Image
Image

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Export Layered Image as .png?

#6 Post 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)
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Export Layered Image as .png?

#7 Post 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.
Image

Image
Image

Post Reply

Who is online

Users browsing this forum: Bing [Bot]