def get_thumb(self, scale, key = None, direction = "thumbnail"): """ Return data from plone scale or None""" #Make cache optional if key is None: key = getattr(self.context, 'blob_key', 'image') cachekey = (self.context.uid, scale, key, direction) cached = self.thumb_cache.get(cachekey) if cached: return cached if direction not in _ALLOWED_SCALE_DIRECTIONS: return scales = get_image_scales() maxwidth, maxheight = scales[scale] blobs = IBlobs(self.context) if key in blobs: registry = get_current_registry() if blobs[key].mimetype in registry.settings['supported_thumbnail_mimetypes']: with blobs[key].blob.open() as f: try: thumb_data, image_type, size = scaleImage( f, width = maxwidth, height = maxheight, direction = direction ) except IOError: #FIXME: Logging? return thumb = Thumbnail(thumb_data, image_type = image_type, size = size) self.thumb_cache.put(cachekey, thumb) return thumb
def thumb_view(context, request, subpath=None): if subpath is None: subpath = request.subpath if len(subpath) != 2: return HTTPNotFound() key = subpath[0] #Usually 'image', the blob area where it's stored scale_name = subpath[1] #Some scale, like 'col-1' scales = get_image_scales() if scale_name not in scales: return HTTPNotFound() thumbnails = request.registry.queryAdapter(context, IThumbnails) if not thumbnails: #Log? raise HTTPNotFound() thumb = thumbnails.get_thumb(scale_name, key=key) if thumb: return Response( body=thumb.image, headerlist=[ # disposition = 'inline' # ('Content-Disposition', '%s;filename="%s"' % ( # disposition, context.filename.encode('ascii', 'ignore'))), ('Content-Type', thumb.mimetype), ('Etag', thumb.etag) ]) raise HTTPNotFound()
def thumb_view(context, request, subpath=None): if subpath is None: subpath = request.subpath if len(subpath) != 2: return HTTPNotFound() key = subpath[0] # Usually 'image', the blob area where it's stored scale_name = subpath[1] # Some scale, like 'col-1' scales = get_image_scales() if scale_name not in scales: return HTTPNotFound() thumbnails = request.registry.queryAdapter(context, IThumbnails) if not thumbnails: # Log? raise HTTPNotFound() thumb = thumbnails.get_thumb(scale_name, key=key) if thumb: return Response( body=thumb.image, headerlist=[ # disposition = 'inline' # ('Content-Disposition', '%s;filename="%s"' % ( # disposition, context.filename.encode('ascii', 'ignore'))), ("Content-Type", thumb.mimetype), ("Etag", thumb.etag), ], ) raise HTTPNotFound()
def images_panel(context, request, va, **kw): response = {'mime_to_title': image_mime_to_title, 'scales': get_image_scales(request.registry)} return render('arche:templates/sysinfo/images.pt', response, request = request)
def thumb_url(request, context, scale, key = None, direction = 'thumbnail'): if key is None: key = getattr(context, 'blob_key', 'image') scales = get_image_scales(request.registry) if scale in scales and IThumbnailedContent.providedBy(context) and key in IBlobs(context, ()): return request.resource_url(context, 'thumbnail', key, scale, direction)