Example #1
0
class NyFSImage(NyFSFile):
    """ """
    width = ''
    height = ''

    def __init__(self, id, title, file, content_type='', precondition=''):
        try:
            id = id()
        except TypeError:
            pass

        self.__name__ = id
        self.title = title
        self.data = ''
        self.size = 0
        self.width = -1
        self.height = -1
        self.content_type = content_type
        self.precondition = precondition
        self._ext_file = ExtImage(id, title)

    def tag(self,
            height=None,
            width=None,
            alt=None,
            scale=0,
            xscale=0,
            yscale=0,
            css_class=None,
            title=None,
            **args):
        return self._ext_file.tag(height=height,
                                  width=width,
                                  alt=alt,
                                  scale=scale,
                                  xscale=xscale,
                                  yscale=yscale,
                                  **args)

    def __str__(self):
        return self.tag()

    def update_data(self, data, content_type=None, size=None):
        file = data
        data, size = self._read_data(data)
        content_type = self._get_content_type(file, data, self.__name__,
                                              'application/octet-stream')
        ct, width, height = getImageInfo(data)
        if ct:
            content_type = ct
        if width >= 0 and height >= 0:
            self.width = width
            self.height = height
        NyFSImage.inheritedAttribute('update_data')(self, data, content_type,
                                                    size)
Example #2
0
class NyFSImage(NyFSFile):
    """ """

    width = ""
    height = ""

    def __init__(self, id, title, file, content_type="", precondition=""):
        try:
            id = id()
        except TypeError:
            pass

        self.__name__ = id
        self.title = title
        self.data = ""
        self.size = 0
        self.width = -1
        self.height = -1
        self.content_type = content_type
        self.precondition = precondition
        self._ext_file = ExtImage(id, title)

    def tag(self, height=None, width=None, alt=None, scale=0, xscale=0, yscale=0, css_class=None, title=None, **args):
        return self._ext_file.tag(
            height=height, width=width, alt=alt, scale=scale, xscale=xscale, yscale=yscale, **args
        )

    def __str__(self):
        return self.tag()

    def update_data(self, data, content_type=None, size=None, filename=""):
        file = data
        data, size = self._read_data(data)
        if not filename:
            filename = getattr(file, "filename", "")
        content_type = self._get_content_type(file, data, self.__name__, "application/octet-stream")
        ct, width, height = getImageInfo(data)
        if ct:
            content_type = ct
        if width >= 0 and height >= 0:
            self.width = width
            self.height = height
        NyFSImage.inheritedAttribute("update_data")(self, data, content_type, size, filename)