momorprods
Jul 01, 2015 - 11:38
Greetings,
I feel a bit stupid, but I'm stuck trying to get the actual size of a named image, loaded in my scene through load_image_file() !
Any clue ?
Thanks !
Greetings,
I feel a bit stupid, but I'm stuck trying to get the actual size of a named image, loaded in my scene through load_image_file() !
Any clue ?
Thanks !
The first problem here is that scene.load_image_file() returns a str (or None).
import scene
img = scene.load_image_file(scene.get_image_path('Snake'))
print(type(img), img) # --> (<type 'str'>, '1B38821FFDAFE1F5B64892BDC5E085B0')
With the ui module, you could do:
import ui
img = ui.Image.named('Snake')
print(img, img.scale, img.size)
But perhaps a better approach would be:
import PIL, scene
# returns a scene_image (str) and size in pixels (w, h)
def load_image_file_with_size(img_file_path):
pil_img = PIL.Image.open(img_file_path)
return scene.load_pil_image(pil_img), pil_img.size
snake_file_path = scene.get_image_path('Snake')
print(load_image_file_with_size(snake_file_path))
agreed, but it's a pity to have to load the image twice - one time for the scene and another time from ui functions to get the size.
Is there a more efficient way ?
See edit above.
Brilliant, thanks !!!