- May 5, 2021
- 226
- 492
Merry Christmas!
I have a class that resizes any image to fit into a specific space (given to me by someone we all know and love but slightly modified). I'm creating a screen that requires frames for these images, so I need to know the dimensions of the images after they've been resized. The code is as follows:
Ideally, the class would also fork out some dimensions for me to apply to a frame but I'll settle for something that just gives me the numbers so I can get this thing done. If anyone could help me by shedding some light on how to do this I would deeply appreciate it.
Thanks everyone.
Edit: I suppose I should also mention that I didn't just post this on a whim. I've tried .get_size() and returning the dimensions from render() within the class and all sorts of other fun stuff. (Stuff that I'm too ashamed to post here.) Thanks again.
I have a class that resizes any image to fit into a specific space (given to me by someone we all know and love but slightly modified). I'm creating a screen that requires frames for these images, so I need to know the dimensions of the images after they've been resized. The code is as follows:
Python:
python:
class Event_Resize(renpy.Displayable):
def __init__(self, img, width=800, height=450, **kwargs):
self.img = img
self.width = float( width )
self.height = float( height )
super(Event_Resize, self).__init__(**kwargs)
def render(self, width, height, st, at):
name = renpy.substitutions.substitute( self.img, translate=False )[0]
if not renpy.loadable( name ):
raise ValueError( "Image '{}' can NOT be found".format( name ) )
img = renpy.easy.displayable( name )
src = renpy.display.im.cache.get( img )
wBase, hBase = src.get_size()
rW = self.width / wBase if wBase > self.width else 1.0
rH = self.height / hBase if hBase > self.height else 1.0
f = min( rW, rH )
rWidth = int( wBase * f )
rHeight = int( hBase * f )
if wBase < self.width and hBase < self.height:
rW = self.width / wBase if wBase < self.width else 1.0
rH = self.height / hBase if hBase < self.height else 1.0
f = min( rW, rH )
rWidth = int( wBase * f )
rHeight = int( hBase * f )
src = renpy.display.scale.real_bilinear( src, ( rWidth, rHeight ) )
r = renpy.Render( rWidth, rHeight )
r.blit( src, ( 0, 0 ) )
return r
Code:
screen screen event_screen():
add frame_I_wish_could_go_here
add event_actor1
label start:
$ event_actor1 = Event_Resize(event_actor1)
call screen event_screen()
Thanks everyone.
Edit: I suppose I should also mention that I didn't just post this on a whim. I've tried .get_size() and returning the dimensions from render() within the class and all sorts of other fun stuff. (Stuff that I'm too ashamed to post here.) Thanks again.
Last edited: