コード例 #1
0
ファイル: apps.py プロジェクト: wagboot/wagboot
    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)))
コード例 #2
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')
)
コード例 #3
0
ファイル: image_formats.py プロジェクト: PARINetwork/pari
        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'))
コード例 #4
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'))