本文整理汇总了Python中plone.scale.storage.AnnotationStorage.scale方法的典型用法代码示例。如果您正苦于以下问题:Python AnnotationStorage.scale方法的具体用法?Python AnnotationStorage.scale怎么用?Python AnnotationStorage.scale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plone.scale.storage.AnnotationStorage
的用法示例。
在下文中一共展示了AnnotationStorage.scale方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_cropped
# 需要导入模块: from plone.scale.storage import AnnotationStorage [as 别名]
# 或者: from plone.scale.storage.AnnotationStorage import scale [as 别名]
def save_cropped(
self, fieldname, field, scale, image_file, interface=None):
""" see interface
"""
handler = IImageScaleHandler(field)
sizes = field.getAvailableSizes(self.context)
w, h = sizes[scale]
data = handler.createScale(
self.context, scale, w, h, data=image_file.read())
# store scale for classic <fieldname>_<scale> traversing
handler.storeScale(self.context, scale, **data)
# call plone.scale.storage.scale method in order to
# provide saved scale for plone.app.imaging @@images view
def crop_factory(fieldname, direction='keep', **parameters):
blob = Blob()
result = blob.open('w')
_, image_format, dimensions = scaleImage(
data['data'], result=result, **parameters)
result.close()
return blob, image_format, dimensions
# call storage with actual time in milliseconds
# this always invalidates old scales
storage = AnnotationStorage(self.context, self.now_millis)
storage.scale(
factory=crop_factory, fieldname=field.__name__, width=w, height=h)
示例2: save_cropped
# 需要导入模块: from plone.scale.storage import AnnotationStorage [as 别名]
# 或者: from plone.scale.storage.AnnotationStorage import scale [as 别名]
def save_cropped(self, fieldname, scale, image_file):
""" see interface
"""
field = self.get_image_field(fieldname)
handler = IImageScaleHandler(field)
sizes = field.getAvailableSizes(self.context)
w, h = sizes[scale]
data = handler.createScale(self.context, scale, w, h, data=image_file.read())
# store scale for classic <fieldname>_<scale> traversing
handler.storeScale(self.context, scale, **data)
# call plone.scale.storage.scale method in order to
# provide saved scale for plone.app.imaging @@images view
def crop_factory(fieldname, direction="keep", **parameters):
blob = Blob()
result = blob.open("w")
_, image_format, dimensions = scaleImage(data["data"], result=result, **parameters)
result.close()
return blob, image_format, dimensions
# Avoid browser cache
# calling reindexObject updates the modified metadate too
self.context.reindexObject()
# call storage with actual time in milliseconds
# this always invalidates old scales
storage = AnnotationStorage(self.context, _millis)
storage.scale(factory=crop_factory, fieldname=field.__name__, width=w, height=h)
示例3: _crop
# 需要导入模块: from plone.scale.storage import AnnotationStorage [as 别名]
# 或者: from plone.scale.storage.AnnotationStorage import scale [as 别名]
def _crop(self, fieldname, scale, box, interface=None):
"""interface just useful to locate field on dexterity types
"""
# https://github.com/plone/plone.app.imaging/blob/ggozad-cropping/src/
# plone/app/imaging/cropping.py
field = self.context.getField(fieldname)
if hasattr(field,'getHandler'):
handler = field.getHandler()
else:
handler = IImageScaleHandler(field)
# TODO this is archetype only
value = field.get(self.context)
data = getattr(aq_base(value), 'data', value)
if isinstance(data, Pdata):
data = str(data)
original_file = StringIO(data)
image = PIL.Image.open(original_file)
image_format = image.format or self.DEFAULT_FORMAT
cropped_image = image.crop(box)
cropped_image_file = StringIO()
cropped_image.save(cropped_image_file, image_format, quality=100)
cropped_image_file.seek(0)
sizes = field.getAvailableSizes(self.context)
#regular scale
if len(sizes[scale]) ==3:
w, h, s = sizes[scale]
data = handler.createScale(self.context, scale, w, h, data=cropped_image_file.read())
else:
w, h = sizes[scale]
data = handler.createScale(self.context, scale, w, h,
data=cropped_image_file.read())
# store scale for classic <fieldname>_<scale> traversing
handler.storeScale(self.context, scale, **data)
# call plone.scale.storage.scale method in order to
# provide saved scale for plone.app.imaging @@images view
def crop_factory(fieldname, direction='keep', **parameters):
blob = Blob()
result = blob.open('w')
_, image_format, dimensions = scaleImage(data['data'],
result=result, **parameters)
result.close()
return blob, image_format, dimensions
# call storage with actual time in milliseconds
# this always invalidates old scales
storage = AnnotationStorage(self.context,
self.now_millis)
storage.scale(factory=crop_factory, fieldname=fieldname,
width=w, height=h)
# store crop information in annotations
self._store(fieldname, scale, box)
示例4: scale
# 需要导入模块: from plone.scale.storage import AnnotationStorage [as 别名]
# 或者: from plone.scale.storage.AnnotationStorage import scale [as 别名]
def scale(self,
fieldname=None,
scale=None,
height=None,
width=None,
direction='thumbnail',
**parameters):
if fieldname is None:
fieldname = IPrimaryFieldInfo(self.context).fieldname
if scale is not None:
available = self.getAvailableSizes(fieldname)
if scale not in available:
return None
width, height = available[scale]
if IDisableCSRFProtection and self.request is not None:
alsoProvides(self.request, IDisableCSRFProtection)
storage = AnnotationStorage(self.context, self.modified)
info = storage.scale(factory=self.create,
fieldname=fieldname,
height=height,
width=width,
direction=direction,
**parameters)
if info is not None:
info['fieldname'] = fieldname
scale_view = ImageScale(self.context, self.request, **info)
return scale_view.__of__(self.context)
示例5: getInfo
# 需要导入模块: from plone.scale.storage import AnnotationStorage [as 别名]
# 或者: from plone.scale.storage.AnnotationStorage import scale [as 别名]
def getInfo(self, fieldname=None, scale=None, height=None, width=None,
**parameters):
storage = AnnotationStorage(self.context, self.modified)
return storage.scale(
factory=self.create,
fieldname=fieldname,
height=height,
width=width,
**parameters)
示例6: scale
# 需要导入模块: from plone.scale.storage import AnnotationStorage [as 别名]
# 或者: from plone.scale.storage.AnnotationStorage import scale [as 别名]
def scale(self, fieldname=None, scale=None, height=None, width=None, **parameters):
if scale is not None:
available = self.getAvailableSizes(fieldname)
if not scale in available:
return None
width, height = available[scale]
if width is None and height is None:
field = self.field(fieldname)
return field.get(self.context)
storage = AnnotationStorage(self.context, self.modified)
info = storage.scale(factory=self.create,
fieldname=fieldname, height=height, width=width, **parameters)
if info is not None:
return self.make(info).__of__(self.context)
示例7: scale
# 需要导入模块: from plone.scale.storage import AnnotationStorage [as 别名]
# 或者: from plone.scale.storage.AnnotationStorage import scale [as 别名]
def scale(self, fieldname=None, scale=None, height=None, width=None, **parameters):
if fieldname is None:
fieldname = IPrimaryFieldInfo(self.context).fieldname
if scale is not None:
available = self.getAvailableSizes(fieldname)
if not scale in available:
return None
width, height = available[scale]
storage = AnnotationStorage(self.context, self.modified)
info = storage.scale(factory=self.create,
fieldname=fieldname, height=height, width=width, **parameters)
if info is not None:
info['fieldname'] = fieldname
scale_view = ImageScale(self.context, self.request, **info)
return scale_view.__of__(self.context)
示例8: __call__
# 需要导入模块: from plone.scale.storage import AnnotationStorage [as 别名]
# 或者: from plone.scale.storage.AnnotationStorage import scale [as 别名]
def __call__(self):
form = self.request.form
size = form.get('size', form.get('s', None))
if size is None:
# return original - no scaling required
return self.context.index_html(self.request, self.request.RESPONSE)
else:
size = int(size)
if not IAttributeAnnotatable.providedBy(self.context):
alsoProvides(self.context, IAttributeAnnotatable)
storage = AnnotationStorage(self.context)
scale = storage.scale(self.scale_factory,
width=size,
height=size)
response = self.request.RESPONSE
response.setHeader('Last-Modified', rfc1123_date(scale['modified']))
response.setHeader('Content-Type', scale['mimetype'])
response.setHeader('Content-Length', len(scale['data']))
response.setHeader('Accept-Ranges', 'bytes')
return scale['data']