Get texture size in px

I’m doing something like:

imgfile = loader.loadTexture("path/file.png")
	print imgfile.getSimpleXSize(), imgfile.getSimpleYSize()
	print imgfile.getOrigFileXSize(), imgfile.getOrigFileYSize()

The getSimpleX/YSize methods print 0 0.
The getOrigFileX/YSize methods print
960
624
for X and
540
264
for the Y method. Why does it return two values and why does it not return a list which can be easily accessed via value[i]?

While 624x264 is the correct size in pixels … where do the 960x540 come from? My screen size is 1920x1200, so that can’t be it. Thing is that might be the size of the parent node. But I request those values long before reparenting the node. The code above is the full snippet.

getOrigFileXSize() and getOrigFileYSize() return one number each. You must be mistaken about the double numbers–maybe you’re seeing the output from two different textures.

Note that getSimpleXSize()/getSimpleYSize() have nothing whatsoever to do with the size of the texture and will generally always return 0, unless you set a “simple” texture image. The “simple” texture image is an advanced feature which is designed to speed texture loads: you can specify a highly-reduced version of the texture as the “simple” texture which will be displayed until the full texture is loaded from disk. It’s only useful if you’re using threaded texture loads to load assets in the background, which is another advanced feature.

David

Alright, I read you on the “simple” method. Not relevant to me (yet).

But the thing with getOrigFileXSize() and getOrigFileYSize() remains. Honestly, the code I posted is the full thing.

imgfile = loader.loadTexture(path/file.png)
print imgfile.getOrigFileXSize()

prints me:

960
624

imgfile = loader.loadTexture(path/file.png)
print imgfile.getOrigFileXSize()
print imgfile.getOrigFileYSize()

prints me:

960
540
624
264

I never came upon this method before, it’s the only part of my game where I use it. If I only print either X or Y, two values are printed on the console, seperated by a new line (I guess from appearance). The 624/264 thing is the texture size, but 960/540 is also printed. It’s not the size of the parent frame (as I thought, because it would fit) - if I change that, 960/540 is still reported. I assume that there’s a little bug(?) here that fetches values from the frame that the image is embedded in, either from the frameSize, image_pos or image_scale attribute of DirectFrame. It would fit because it has a 16:9 ratio and I use calculations like xright*0.8/480 setting up the DirectFrame. Maybe it’s even platform-specific.

On the other hand all that can’t be because I request the getOrigFileXSize method right after loading the image, before defining the embedding DirectFrame.

I still say you’re seeing something different. I bet you’re calling this code twice, for two different textures, without realizing it.

Try to write the code to determine precisely where it is printing the bogus numbers:

print "Loading texture."
imgfile = loader.loadTexture('path/file.png')
print "loaded texture %s" % (imgfile)
print "getting x size"
x = imgfile.getOrigFileXSize()
print "getting y size"
y = imgfile.getOrigFileYSize()
print "xsize is %s" % (repr(x))
print "ysize is %s" % (repr(y))

David

Trying your code I realized you’re right: I accidentely called this thing twice. Works fine actually.