Exemplo n.º 1
0
    def ready(self):
        unregister_image_format('left')
        unregister_image_format('right')
        unregister_image_format('fullwidth')

        for align in ('centered', 'left', 'right', 'inline'):
            register_image_format(Format('{}-original'.format(align), '{}, original size'.format(align.capitalize()), 'richtext-image {}'.format(align), 'original'))
            for size in ('42', '50', '72', '100', '200', '500', '800'):
                register_image_format(
                    Format('{}-{}'.format(align, size),
                           '{}, {}px'.format(align.capitalize(), size),
                           'richtext-image {}'.format(align), 'width-{s}'.format(s=size)))
Exemplo n.º 2
0
from wagtail.wagtailimages.formats import Format, register_image_format, unregister_image_format

unregister_image_format('fullwidth')
register_image_format(
    Format('fullwidth', 'Full width',
           'richtext-image full-width img-responsive', 'width-800'))

unregister_image_format('left')
register_image_format(
    Format('left', 'Left-aligned', 'richtext-image left img-responsive',
           'width-500'))

unregister_image_format('right')
register_image_format(
    Format('right', 'Right-aligned', 'richtext-image right img-responsive',
           'width-500'))
Exemplo n.º 3
0
    def image_to_html(self, image, alt_text, extra_attributes=''):
        rendition = image.get_rendition(self.filter_spec)

        if self.classnames:
            class_attr = 'class="%s" ' % escape(self.classnames)
        else:
            class_attr = ''

        return """<figure %s%s>
            <img src="%s" width="%d" height="%d" alt="%s" />
            <figcaption class="a4">%s</figcaption>
        </figure>""" % (
            extra_attributes, class_attr,
            escape(rendition.url), rendition.width, rendition.height, alt_text,
            image.caption_html()
        )

unregister_image_format('fullwidth')
unregister_image_format('left')
unregister_image_format('right')

register_image_format(
    CaptionedImageFormat('fullwidth', 'Full width', 'bodytext-image', 'width-750')
)
register_image_format(
    CaptionedImageFormat('left', 'Half width left aligned', 'bodytext-image small left', 'width-400')
)
register_image_format(
    CaptionedImageFormat('right', 'Half width right aligned', 'bodytext-image small right', 'width-400')
)
Exemplo n.º 4
0
from wagtail.wagtailimages.formats import (Format, register_image_format,
                                           unregister_image_format)

register_image_format(
    Format('small_image_left', 'Small Image Left',
           'richtext-image small_image_left left', 'width-540'))

unregister_image_format('left')
unregister_image_format('right')
Exemplo n.º 5
0
        try:
            half_rendition = image.get_rendition('max-512x410')
        except SourceImageIOError:
            # Image file is (probably) missing from /media/original_images - generate a dummy
            # rendition so that we just output a broken image, rather than crashing out completely
            # during rendering
            Rendition = image.renditions.model  # pick up any custom Image / Rendition classes that may be in use
            half_rendition = Rendition(image=image, width=0, height=0)
            half_rendition.file.name = 'not-found'

        if self.classnames:
            class_attr = 'class="%s" ' % escape(self.classnames)
        else:
            class_attr = ''

        sizes = "(max-width: 480px) 512w, 100vw"
        srcset = "%s 512w, %s" % (escape(half_rendition.url),
                                  escape(rendition.url))
        return ('<img %s%s '
                'width="%d" height="%d" '
                'alt="%s" srcset="%s" sizes="%s">') % (
                    extra_attributes, class_attr,
                    rendition.width, rendition.height, alt_text,
                    srcset, sizes
                )


register_image_format(Format('halfwidth', 'Half Width (512px)', 'richtext-image half-width', 'max-512x410'))
unregister_image_format("fullwidth")
register_image_format(FullWidthImgFormat('fullwidth', 'Full width', 'richtext-image full-width', 'max-1400x1120'))
Exemplo n.º 6
0
# image_formats.py
from wagtail.wagtailimages.formats import Format, unregister_image_format, register_image_format

unregister_image_format('fullwidth')
register_image_format(Format('fullwidth', 'Fullwidth', 'richtext-image fullwidth', 'max-1200x1200'))