示例#1
0
    def __blank_tile_default(self):
        import pkg_resources
        import Image as pil
        import ImageDraw
        import ImageFont

        im = pil.new('RGB', (256, 256), (234, 224, 216))

        text = 'Image not available'
        try:
            font_file = pkg_resources.resource_filename(
                'mapping.enable', 'fonts/Verdana.ttf')
            font = ImageFont.truetype(font_file, 18)
        except IOError:
            font = ImageFont.load_default()
        size = font.getsize(text)
        pos = (256 - size[0]) // 2, (256 - size[1]) // 2

        draw = ImageDraw.Draw(im)
        draw.text(pos, text, fill=(200, 200, 200), font=font)
        del draw

        tile = StringIO()
        im.save(tile, format='png')
        return Image(StringIO(tile.getvalue()))
示例#2
0
def gc_image_for(name, path=None):
    "Convert an image file name to a cached Kiva gc containing the image"
    global _app_path, _enable_path
    filename = abspath(name)
    image = _image_cache.get(filename)
    if image is None:
        cachename = filename
        if path is not None:
            zip_path = abspath(path + '.zip')
            zip_file = _zip_cache.get(zip_path)
            if zip_file is None:
                if is_zipfile(zip_path):
                    zip_file = ZipFile(zip_path, 'r')
                else:
                    zip_file = False
                _zip_cache[zip_path] = zip_file
            if isinstance(zip_file, ZipFile):
                try:
                    filename = StringIO(zip_file.read(name))
                except:
                    pass
        try:
            _image_cache[cachename] = image = Image(filename)
        except:
            _image_cache[filename] = info = sys.exc_info()[:2]
            raise info[0], info[1]
    elif type(image) is TupleType:
        raise image[0], image[1]
    return image
示例#3
0
    def fromfile(cls, filename):
        """ Alternate constructor to create an ImageData from an image file
        on disk. 'filename' may be a file path or a file object.
        """

        from kiva.image import Image
        img = Image(filename)
        imgdata = cls(data=img.bmp_array, transposed=False)
        fmt = img.format()

        if fmt == "rgb24":
            imgdata.value_depth = 3
        elif fmt == "rgba32":
            imgdata.value_depth = 4
        else:
            raise ValueError("Unknown image format in file %s: %s" %
                             (filename, fmt))
        return imgdata
示例#4
0
 def test_initialization(self):
     image = Image(self.filename)
     self.assertEqual(image.width(), 100)
     self.assertEqual(image.height(), 120)
     self.assertEqual(image.format(), 'rgb24')
示例#5
0
    def __init__(self, *args, **kw):
        super(ToolbarButton, self).__init__(*args, **kw)

        image_resource = ImageResource(self.image)
        self._image = Image(image_resource.absolute_path)
示例#6
0
 def _filename_changed(self, new):
     self._marker = Image(new)
示例#7
0
 def _tile_cache_changed(self, new):
     new.process_raw = lambda d: Image(StringIO(d))