Page 1 of 1

JPG transparency

Posted: Fri Nov 15, 2013 10:50 pm
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.

Re: JPG transparency

Posted: Sat Nov 16, 2013 2:00 am
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.

Re: JPG transparency

Posted: Sat Nov 16, 2013 2:52 am
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)

Re: JPG transparency

Posted: Sun Nov 17, 2013 6:17 pm
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.

Re: JPG transparency

Posted: Thu Nov 21, 2013 7:44 pm
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)

Re: JPG transparency

Posted: Sun Nov 24, 2013 8:42 pm
by ananassa
Image

It works! Thank you very much.