Kodi Community Forum
Getting image proportions - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: Getting image proportions (/showthread.php?tid=10625)



- Abo-Jo - 2005-03-13

i'm writing a script to grab an image from a website and there is no guarantee of the image's size. it can fluctuate.

at the moment i have it all done excpet for the display.

does anyone know any code which will get the image's size and scale it in proprtion on screen. ideally i need it to be 80% or so of the screen width and the image is always in landscape.

much appreciated.


- jmarshall - 2005-03-13

if you use a guiimage object to display it, then just setting it's width to what you want, then setting it to keep the aspect ratio will do the trick. i'm not sure how much of the underlying control is exposed via python.

perhaps some python gurus can fill us in?


- solexalex - 2005-03-13

never tried but have a look in the pil (python imaging library) maybe some functions will do the tricks !
keep in touch


- Abo-Jo - 2005-03-13

ok, this is where i have got to so far. i've gone and grabbed the images i want and i have found that they are actually teh same size in gif and a differnet size in jpg. these sizes actually stay the same which helps me a lot.

here is my displaying function.

Quote:def showimage( self, localcopy ):
if localcopy[-4:] == ".jpg":
picsize = (725, 525)
if localcopy[-4:] == ".gif":
picsize = (600, 214)
if emulating:
picture= xbmcgui.controlimage(0, 0, picsize[0],picsize[1], localcopy)
self.addcontrol(picture)

however, what i'm finding is that if i try to change this to scale it:

Quote:picture= xbmcgui.controlimage(0, 0, picsize[0],picsize[1], localcopy)

the image stays the same size and is actually bigger than my screen. so far i've only tried this on the emulator but an earlier attempt had the start position 0,0 totally off screen and useless. this is on a pal system by the way.

does the image have to be its original size or can it be shrunk?


- Abo-Jo - 2005-03-14

pil is working out nicely on the emulator, going to do a bit of testing on the xb asap and will post results when i have them.


- solexalex - 2005-03-14

nice Wink