@staticmethod def _load_tile(filename): try: surface = cairo.ImageSurface.create_from_png(filename) except MemoryError: # Try JPEG. Load jpeg image, add alpha channel (32 bits), create imagesurface pixbuf24 = gtk.gdk.pixbuf_new_from_file(filename) pixbuf = pixbuf24.add_alpha(False, chr(0), chr(0), chr(0)) pix_data = pixbuf.get_pixels_array() surface = cairo.ImageSurface.create_for_data(pix_data, cairo.FORMAT_RGB24, pixbuf.get_width(), pixbuf.get_height(), pixbuf.get_rowstride()) if surface.get_width() != surface.get_height(): raise Exception("Image too small, probably corrupted file") return surface