示例#1
0
def thumb_url(image, request, size):
    """
    Return the url for displaying the image with dimensions bounded by given
    size.
    """
    assert IImage.providedBy(image), "Cannot take thumbnail of non-image."
    return model_url(image, request, 'thumb', '%dx%d.jpg' % size)
示例#2
0
def thumbnail_view(context, request):
    assert IImage.providedBy(context), "Context must be an image."
    filename = request.subpath[0] # <width>x<length>.jpg
    size = map(int, filename[:-4].split('x'))
    thumb = context.thumbnail(tuple(size))

    # XXX Allow browser caching be setting Last-modified and Expires
    #     and respecting If-Modified-Since requests with 302 responses.
    data = thumb.blobfile.open().read()
    return Response(body=data, content_type=thumb.mimetype)
示例#3
0
    def test_jpg(self):
        from opencore.models.interfaces import IImage
        from pkg_resources import resource_stream
        stream = resource_stream('opencore.models.tests', 'test.jpg')
        o = self._makeOne(stream=stream, mimetype='image/jpeg')
        self.failUnless(o.is_image)
        self.failUnless(IImage.providedBy(o))
        self.assertEqual(o.image_size, (600, 400))
        self.assertEqual(o.image().size, (600, 400))

        from zope.interface.verify import verifyObject
        verifyObject(IImage, o)
示例#4
0
    def test_instance_has_valid_construction(self):
        instance = self._makeOne()
        self.assertEqual(instance.title, u'title')
        self.assertEqual(instance.creator, u'admin')
        self.assertEqual(instance.modified_by, u'admin')
        self.assertEqual(instance.blobfile.open().read(), 'FAKECONTENT')
        self.assertEqual(instance.size, 11)
        self.assertEqual(instance.mimetype, 'text/plain')
        self.assertEqual(instance.filename, 'afile.txt')
        self.failIf(instance.is_image)

        from opencore.models.interfaces import IImage
        self.failIf(IImage.providedBy(instance))
示例#5
0
 def uri(self):
     if IImage.providedBy(self.context):
         return thumb_url(self.context, self.request, (75,75))    
     return model_url(self.context, self.request)