示例#1
0
def retrieveScale(self, instance, scale):
    """ retrieve a scaled version of the image """
    field = self.context
    if scale is None:
        blob = field.getUnwrapped(instance)
        data = dict(
            id=field.getName(), blob=blob.getBlob(), content_type=blob.getContentType(), filename=blob.getFilename()
        )
    else:
        fields = getattr(aq_base(instance), blobScalesAttr, {})
        scales = fields.get(field.getName(), {})
        data = scales.get(scale)
    if data is not None:
        blob = openBlob(data["blob"])
        # `updata_data` & friends (from `OFS`) should support file
        # objects, so we could use something like:
        #   ImageScale(..., data=blob.getIterator(), ...)
        # but it uses `len(data)`, so we'll stick with a string for now
        image = ImageScale(
            data["id"],
            data=blob.read(),
            blob=data["blob"],
            filename=data["filename"],
            content_type=data["content_type"],
        )
        blob.close()
        return image.__of__(instance)
    return None
示例#2
0
 def storeScale(self, instance, scale, **data):
     """ store a scaled version of the image """
     image = ImageScale(**data)
     field = self.context
     field.getStorage(instance).set(
         image.getId(), instance, image, mimetype=image.content_type, filename=image.filename
     )
示例#3
0
 def storeScale(self, instance, scale, **data):
     """ store a scaled version of the image """
     image = ImageScale(**data)
     field = self.context
     field.getStorage(instance).set(image.getId(),
                                    instance,
                                    image,
                                    mimetype=image.content_type,
                                    filename=image.filename)
示例#4
0
 def make(self, info):
     """ instantiate an object implementing `IImageScale` """
     mimetype = info['mimetype']
     info['content_type'] = mimetype
     info['filename'] = self.context.getFilename()
     scale = ImageScale(info['uid'], **info)
     scale.size = len(scale.data)
     url = self.context.absolute_url()
     extension = mimetype.split('/')[-1]
     scale.url = '%s/@@images/%s.%s' % (url, info['uid'], extension)
     return scale
示例#5
0
 def make(self, info):
     """ instantiate an object implementing `IImageScale` """
     mimetype = info["mimetype"]
     info["content_type"] = mimetype
     info["filename"] = self.context.getFilename()
     scale = ImageScale(info["uid"], **info)
     scale.size = len(scale.data)
     url = self.context.absolute_url()
     extension = mimetype.split("/")[-1]
     scale.url = "%s/@@images/%s.%s" % (url, info["uid"], extension)
     return scale
示例#6
0
 def make(self, info):
     """ instantiate an object implementing `IImageScale` """
     mimetype = info['mimetype']
     info['content_type'] = mimetype
     info['filename'] = self.context.getFilename()
     scale = ImageScale(info['uid'], **info)
     scale.size = len(scale.data)
     url = self.context.absolute_url()
     extension = mimetype.split('/')[-1]
     scale.url = '%s/@@images/%s.%s' % (url, info['uid'], extension)
     return scale