Getting image size

490 views
Skip to first unread message

Math BKweb

unread,
May 18, 2013, 4:47:45 AM5/18/13
to kivy-...@googlegroups.com
Hi Kivy Users and Developpers

I managed to get png picture size with this :

def get_png_size(png_path):
    curdir = dirname(__file__)+'/'
    size = [0,0]   
    f = open( curdir + png_path)
    if f:
        f.seek(12)  # debut du marqueur chaine contenant : ihdr
        ihdr = f.read(4)
        if ihdr == 'IHDR':
            sWidth = f.read(4)
            size[0] = int(sWidth.encode('hex'), 16)
            sHeight = f.read(4)
            size[1] = int(sHeight.encode('hex'),16)
        else:
            print "IHDR tag not found, wrong png format"
        f.close();
    return size


Is this some kind of overbombing ?  I am new to Python, Kivy and mobile devices. Sort of caveman ;)
How can I make it in a cleaner way ?

Thanks for answers
PS: Kivy is great

Akshay Arora

unread,
May 18, 2013, 1:26:36 PM5/18/13
to kivy-...@googlegroups.com
if you want to do this in batches what you are doing could be efficient, though you can also do::

    from kivy.uix.image Import Image
   
    img = Image(source='path/to/image')
    print img.texture.size

As a down side this probably might not be as efficient for batch operations. You should look into using PIL Python Imaging Library or similar python libraries depending on your exact needs. I.E if your needs aren't full filled by functions exposed by kivy.

Best Regards




--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Math BKweb

unread,
May 19, 2013, 2:54:16 AM5/19/13
to kivy-...@googlegroups.com
Great

Thanks Qua-Non, img.texture.size is what I needed.

I have RTFM many times, and still do, but I missed that one.

Best regards

Mathieu Virbel

unread,
Jun 15, 2013, 9:29:54 PM6/15/13
to kivy-...@googlegroups.com
Hi

Kivy is a toolkit for UI. Just having an image size without loading completly it is not in our scope.

Mathieu

Reply all
Reply to author
Forward
0 new messages