Can I return the width of an image?

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
kuroi
Regular
Posts: 129
Joined: Fri Jun 29, 2007 10:50 am
Location: Albuquerque, New Mexico, USA
Contact:

Can I return the width of an image?

#1 Post by kuroi » Sat Jun 19, 2010 12:23 pm

Hi out there in Renpy land~

I'm working on an update to the Kuroi Games manga engine and I can't seem to find a rather simple function that I'd like to use. Is there a function in Renpy which will return the width in pixels of an image? I was hoping to find something such as:

Code: Select all

image p0f = "frames/intmanga000f.png"
$ p0f_width = p0f.getwidth()
It's simple enough that I have to assume that Renpy has a function which does this that is used somewhere in the guts of the code but I can't for the life of me find it in the Renpy documentation. Does anyone have any ideas? Anyone else had to track down this function and could maybe point me in the right direction?

Thanks a ton
~Kuroi
President, Planner, and Programmer for Kuroi Games!

User avatar
Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: Can I return the width of an image?

#2 Post by Jake » Sat Jun 19, 2010 1:10 pm

kuroi wrote:Hi out there in Renpy land~

I'm working on an update to the Kuroi Games manga engine and I can't seem to find a rather simple function that I'd like to use. Is there a function in Renpy which will return the width in pixels of an image?
~Kuroi
The short version is "yes, but it's buried fairly deep". Here's a thread in which I explained the method to Jack Norton a while ago - I get the impression that PyTom doesn't really expect people to do stuff like this, you're normally supposed to just know the sizes of the images you load in before you load them.
Server error: user 'Jake' not found

User avatar
kuroi
Regular
Posts: 129
Joined: Fri Jun 29, 2007 10:50 am
Location: Albuquerque, New Mexico, USA
Contact:

Re: Can I return the width of an image?

#3 Post by kuroi » Sat Jun 19, 2010 4:12 pm

Thank you!! I'm always happy to find a use programing in a way that means I don't actually have to know something. Soon I'll have built enough code that I'll never have to know anything at all!! MUAHAHAHAHA!!
President, Planner, and Programmer for Kuroi Games!

User avatar
kuroi
Regular
Posts: 129
Joined: Fri Jun 29, 2007 10:50 am
Location: Albuquerque, New Mexico, USA
Contact:

Re: Can I return the width of an image?

#4 Post by kuroi » Sun Jul 04, 2010 2:10 pm

After using this method to find the size of a displayable within my game code, I've found that this works really well with a single terribly annoying exception.

I find that I cannot use this method to find the size of a displayable during init.

When attempt to call a function containing this code during init such as:

Code: Select all

init -10 python:
def make_lcomp(myimage):
myDisplayable = im.Image(myimage)
                myRender = renpy.render(myDisplayable, 800, 600, 0, 0)
                sizes = myRender.get_size()
return LiveComposite ( sizes, (0,0), myimage)

init:
my_lcomp = make_lcomp("images/myimage.png")
If I were to call this code, I would recieve the error:
AttributeError: 'NoneType' object has no attribute 'frame_time'

I've not been able to find a way around this and it would be kinda rough having to manually enter the sizes of all of the images which I'm trying to use this function for. Is there perhaps a way around this?

lol The poor girl who's doing the data entry part of the manga engine is pretty overworked as it is.
President, Planner, and Programmer for Kuroi Games!

User avatar
PyTom
Ren'Py Creator
Posts: 15437
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: Can I return the width of an image?

#5 Post by PyTom » Sun Jul 04, 2010 2:55 pm

If we restrict this to only be image manipulators, the answer is yes. You can run the code:

Code: Select all

renpy.image_size("foo.jpg")
and it will load foo.jpg and return the size. This is a fairly terrible thing to do, though, as it means your game will have to read in all the data during start up, which could slow startup quite a bit. The init code runs before the splashscreen, so they'll only be the presplash to keep them entertained. Also, this will often be read from a cold disk cache.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
barsunduk
Newbie
Posts: 12
Joined: Fri Jul 18, 2014 1:06 pm
Contact:

Re: Can I return the width of an image?

#6 Post by barsunduk » Sat Dec 05, 2015 10:04 am

PyTom wrote:

Code: Select all

renpy.image_size("foo.jpg")
unfortunately it doesn't working if using «build.classify('game/**', 'archive')» to hide game content.

Post Reply

Who is online

Users browsing this forum: No registered users