JPG transparency

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
ananassa
Newbie
Posts: 5
Joined: Wed Nov 06, 2013 5:49 pm
Location: TX, US

JPG transparency

#1 Post by ananassa »

Now, if originally the files were in PNG format, then I wouldn't even have to convert them, everything would be all fine and good. I'm not trying to save space.
But my issue is the images in this game are all JPG, and everything with transparency already has its mask attached. Like so (actual example):

Image

I'd like to be able to use the original sprites without converting or tampering with them.
Is this possible at all in Ren'Py? Because I would really hate to have to put them all through Photoshop and such.

SundownKid
Lemma-Class Veteran
Posts: 2299
Joined: Mon Feb 06, 2012 9:50 pm
Completed: Icebound, Selenon Rising Ep. 1-2
Projects: Selenon Rising Ep. 3-4
Organization: Fastermind Games
Deviantart: sundownkid
Location: NYC
Contact:

Re: JPG transparency

#2 Post by SundownKid »

This is the only way I know of to use transparent jpgs with Ren'py. (The mask has to be separate). Otherwise, you'll have to run them through Photoshop unless there's another converter that can do them in bulk.

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: JPG transparency

#3 Post by PyTom »

you could use im.AlphaMask with im.Crop to do this.

Code: Select all

init python:
    def Masked(filename, width, height):
         return im.AlphaMask(im.Crop(filename, (0, 0, width, height)), im.Crop(filename, (width, 0, width, height)))

image test = Masked("test.jpg", 400, 400)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

ananassa
Newbie
Posts: 5
Joined: Wed Nov 06, 2013 5:49 pm
Location: TX, US

Re: JPG transparency

#4 Post by ananassa »

Image

That's certainly progress, but not quite there. Thanks though.


Switching the im.Crop order gives me this:

Image

I'm... not very good at these sorts of things, as you can see.

Megaman Z
Miko-Class Veteran
Posts: 829
Joined: Sun Feb 20, 2005 8:45 pm
Projects: NaNoRenO 2016, Ren'Py tutorial series
Location: USA
Contact:

Re: JPG transparency

#5 Post by Megaman Z »

Looks like your mask is inverted - traditionally, for image masks, the black pixels are transparent while the light pixels are opaque.

tweaking PyTom's code to account for this, I think this should do the trick:

Code: Select all

init python:
    matrix_invert =  [ -1,  0,  0, 0, 1,
                        0, -1,  0, 0, 1,
                        0,  0, -1, 0, 1,
                        0,  0,  0, 1, 0, ]
    def Masked(filename, width, height):
         return im.AlphaMask(im.Crop(filename, (0, 0, width, height)),
                             im.MatrixColor(im.Crop(filename, (width, 0, width, height)), matrix_invert))

image test = Masked("test.jpg", 400, 400)
(Also, there are a couple spots on your image that I think should be transparent, but the mask itself has to be fixed for that)
~Kitsune Zeta

ananassa
Newbie
Posts: 5
Joined: Wed Nov 06, 2013 5:49 pm
Location: TX, US

Re: JPG transparency

#6 Post by ananassa »

Image

It works! Thank you very much.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot]