Example #1
0
    def test_other_images(self):
        image = zeit.content.image.image.LocalImage()
        image.open('w').write(
            pkg_resources.resource_string(__name__, 'testdata/01.jpg'))
        self.repository['group']['foo-240x120.jpg'] = image
        self.assertAPI([{
            'url':
            'http://localhost/++skin++cms/repository/group/foo-240x120.jpg',
            'name': 'foo-240x120.jpg',
            'scale_name': 'foo-240x120'
        }])

        # Another image
        image = zeit.content.image.image.LocalImage()
        image.open('w').write(
            pkg_resources.resource_string(__name__, 'testdata/02.jpg'))
        self.repository['group']['foo-artikel.jpg'] = image
        transaction.commit()
        self.assertAPI([{
            'url':
            'http://localhost/++skin++cms/repository/group/foo-240x120.jpg',
            'name': 'foo-240x120.jpg',
            'scale_name': 'foo-240x120'
        }, {
            'url':
            'http://localhost/++skin++cms/repository/group/foo-artikel.jpg',
            'name': 'foo-artikel.jpg',
            'scale_name': 'foo-artikel'
        }])
Example #2
0
 def _update_favicon(self):
     split = urlparse.urlsplit(self.url)
     favicon_url = urlparse.urlunsplit((split.scheme, split.netloc, "/favicon.ico", "", ""))
     try:
         icon = urllib2.urlopen(favicon_url, timeout=30).read()
     except urllib2.URLError:
         self.favicon = None
         return
     image = zeit.content.image.image.LocalImage()
     image.open("w").write(icon)
     image_name = self.__name__ + ".ico"
     feed_in_repository = zeit.cms.interfaces.ICMSContent(self.uniqueId)
     feed_in_repository.__parent__[image_name] = image
     self.favicon = feed_in_repository.__parent__[image_name].uniqueId
def create_local_image(filename):
    image = zeit.content.image.image.LocalImage(mimeType='image/jpeg')
    fh = image.open('w')
    file_name = pkg_resources.resource_filename(
        __name__, 'browser/testdata/%s' % filename)
    fh.write(open(file_name, 'rb').read())
    fh.close()
    return image
def create_image_group_with_master_image(file_name=None):
    repository = zope.component.getUtility(
        zeit.cms.repository.interfaces.IRepository)
    if file_name is None:
        file_name = 'DSC00109_2.JPG'
        fh = repository['2006'][file_name].open()
    else:
        fh = open(file_name)
    extension = os.path.splitext(file_name)[-1].lower()

    group = zeit.content.image.imagegroup.ImageGroup()
    group.master_image = u'master-image' + extension
    repository['group'] = group
    image = zeit.content.image.image.LocalImage()
    image.mimeType = mimetypes.types_map[extension]
    image.open('w').write(fh.read())
    repository['group'][group.master_image] = image
    return repository['group']
Example #5
0
def create_local_image(filename, path='browser/testdata/'):
    image = zeit.content.image.image.LocalImage()
    fh = image.open('w')
    file_name = pkg_resources.resource_filename(__name__,
                                                '%s%s' % (path, filename))
    fh.write(open(file_name, 'rb').read())
    fh.close()
    image.__name__ = filename
    return image
def add_image(folder, filename, name=None):
    if name is None:
        name = filename

    filename = pkg_resources.resource_filename(
        __name__, 'browser/testdata/' + filename)
    test_data = open(filename, 'rb').read()

    image = zeit.content.image.image.LocalImage()
    image.__name__ = name
    image.contentType = 'image/jpeg'
    image.open('w').write(test_data)

    metadata = zeit.content.image.interfaces.IImageMetadata(image)
    metadata.copyrights = ((u'ZEIT online', u'http://www.zeit.de'), )
    metadata.caption = u'Nice image'

    repository = zope.component.getUtility(
        zeit.cms.repository.interfaces.IRepository)
    repository[folder][name] = image
Example #7
0
def add_image(folder, filename, name=None):
    if name is None:
        name = filename

    filename = pkg_resources.resource_filename(__name__,
                                               'browser/testdata/' + filename)
    test_data = open(filename, 'rb').read()

    image = zeit.content.image.image.LocalImage()
    image.__name__ = name
    image.contentType = 'image/jpeg'
    image.open('w').write(test_data)

    metadata = zeit.content.image.interfaces.IImageMetadata(image)
    metadata.copyright = ((u'ZEIT online', u'http://www.zeit.de'), )
    metadata.caption = u'Nice image'

    repository = zope.component.getUtility(
        zeit.cms.repository.interfaces.IRepository)
    repository[folder][name] = image
Example #8
0
def create_image_group_with_master_image(file_name=None):
    repository = zope.component.getUtility(
        zeit.cms.repository.interfaces.IRepository)
    if file_name is None:
        file_name = 'DSC00109_2.JPG'
        fh = repository['2006'][file_name].open()
    else:
        try:
            fh = zeit.cms.interfaces.ICMSContent(file_name).open()
        except TypeError:
            fh = open(file_name, 'rb')
    extension = os.path.splitext(file_name)[-1].lower()

    group = zeit.content.image.imagegroup.ImageGroup()
    group.master_images = (('desktop', u'master-image' + extension), )
    repository['group'] = group
    image = zeit.content.image.image.LocalImage()
    image.open('w').write(fh.read())
    repository['group'][group.master_image] = image
    return repository['group']
Example #9
0
def create_local_image(filename, path='browser/testdata/'):
    filetype = filename.rsplit('.', 1)[-1].lower()
    if filetype == 'jpg':
        image = zeit.content.image.image.LocalImage(mimeType='image/jpeg')
    else:
        image = zeit.content.image.image.LocalImage(
            mimeType="image/{}".format(filetype))
    fh = image.open('w')
    file_name = pkg_resources.resource_filename(__name__,
                                                '%s%s' % (path, filename))
    fh.write(open(file_name, 'rb').read())
    fh.close()
    return image
Example #10
0
File: store.py Project: louika/vivi
    def store(self, name, pil_image):
        image = zeit.content.image.image.LocalImage()
        image_format = zeit.content.image.interfaces.IMasterImage(
            self.context).format
        # Luckily, PIL simply ignores kwargs that are not supported by a
        # format, so we can always specify quality, even though it only makes
        # sense for JPEG, but not PNG.
        pil_image.save(
            image.open('w'), image_format, optimize=True, quality=80)
        extension = image_format.lower()
        # XXX Ugly heuristic, but using .jpg is not only generally nicer, but
        # also backwards-compatible behaviour.
        if extension == 'jpeg':
            extension = 'jpg'
        image_name = '%s-%s.%s' % (self.context.__name__, name, extension)
        self.context[image_name] = image

        return image