Пример #1
0
class AbstractConfig(object):

    base = None
    logo = None
    mobile_logo = None
    favicon = None
    primary_logo_scale = None

    def __init__(self, **kwargs):
        if 'base' not in kwargs:
            raise ConfigurationError('A base svg is required')

        self.base = Image(filename=kwargs['base'])

        if 'logo' in kwargs:
            self.logo = Image(filename=kwargs['logo'])
        if 'mobile' in kwargs:
            self.mobile_logo = Image(filename=kwargs['mobile'])
        if 'favicon' in kwargs:
            self.favicon = Image(filename=kwargs['favicon'])

        if 'height' in kwargs:
            # Update by reference the transformer with the new height
            SCALES['LOGOS']['LOGO'] = make_transformer(height=kwargs['height'])
        if 'mobile_height' in kwargs:
            # Update by reference the transformer with the new height
            SCALES['LOGOS']['MOBILE_LOGO'] = make_transformer(
                height=kwargs['mobile_height'])

        self.cachekey = get_cachekey_from_blob(
            self.base.make_blob(),
            self.logo and self.logo.make_blob() or None,
            self.mobile_logo and self.mobile_logo.make_blob() or None,
            self.favicon and self.favicon.make_blob() or None,
        )
        self.scales = {}
        self.collect_scales()
        self.set_primary_logo_scale(**kwargs)

    def add_scale(self, name, scale):
        self.scales[name] = scale

    def collect_scales(self):
        raise NotImplemented()  # pragma: no cover

    def get_scale(self, name):
        return self.scales[name]

    def set_primary_logo_scale(self, **kwargs):
        if 'primary_logo_scale' in kwargs:
            self.primary_logo_scale = kwargs['primary_logo_scale']
Пример #2
0
    def __init__(self, **kwargs):
        if 'base' not in kwargs:
            raise ConfigurationError('A base svg is required')

        self.base = Image(filename=kwargs['base'])

        if 'logo' in kwargs:
            self.logo = Image(filename=kwargs['logo'])
        if 'mobile' in kwargs:
            self.mobile_logo = Image(filename=kwargs['mobile'])
        if 'favicon' in kwargs:
            self.favicon = Image(filename=kwargs['favicon'])

        if 'height' in kwargs:
            # Update by reference the transformer with the new height
            SCALES['LOGOS']['LOGO'] = make_transformer(height=kwargs['height'])
        if 'mobile_height' in kwargs:
            # Update by reference the transformer with the new height
            SCALES['LOGOS']['MOBILE_LOGO'] = make_transformer(
                height=kwargs['mobile_height'])

        self.cachekey = get_cachekey_from_blob(
            self.base.make_blob(),
            self.logo and self.logo.make_blob() or None,
            self.mobile_logo and self.mobile_logo.make_blob() or None,
            self.favicon and self.favicon.make_blob() or None,
        )
        self.scales = {}
        self.collect_scales()
        self.set_primary_logo_scale(**kwargs)
Пример #3
0
 def raw(src):
     return Image(src, 'svg')
Пример #4
0
 def transformer(src):
     img = Image(src, extension)
     img.transform(resize='{}x{}'.format(width, height))
     return img
Пример #5
0
 def resizer(src):
     img = Image(src, extension)
     img.sample(width, height)
     return img
Пример #6
0
 def __init__(self, blobImage):
     base_img = Image(blob=blobImage.data, format='svg')
     self.cachekey = get_cachekey_from_blob(blobImage.data)
     self.scales = {}
     self.collect_scales(base_img)
Пример #7
0
from ftw.logo.converter import convert
from ftw.logo.image import Image
from unittest import TestCase
import os

source = os.path.join(os.path.dirname(__file__), 'fixtures/logo.svg')
base = Image(filename=source)


class TestConverter(TestCase):
    def assertImage(self, img, width, height, format=None, blob=None):
        self.assertEqual(img['width'], width)
        self.assertEqual(img['height'], height)
        if format:
            self.assertEqual(img['format'].lower(), format.lower())
        if blob:
            self.assertEqual(img['data'], blob)

    def test_rejects_unsupported_types(self):
        with self.assertRaises(Exception) as context:
            convert(base, 'UNKNOWN')

        self.assertTrue('scale: UNKNOWN is not supported' in context.exception)

    def test_converts_svg_base(self):
        self.assertImage(
            convert(base, 'BASE'), 1, 1, 'svg',
            '<?xml version="1.0" encoding="UTF-8"?>\n'
            '<svg width="1px" height="1px" viewBox="0 0 1 1" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">\n'
            '    <g id="logo"></g>\n'
            '</svg>\n')
Пример #8
0
 def transformer(img):
     img = img.clone()
     img.transform(resize='{}x{}'.format(width, height))
     return Image(image=img.convert(extension))
Пример #9
0
 def resizer(img):
     img = img.clone()
     img.sample(width, height)
     return Image(image=img.convert(extension))