diff --git a/examples/bootstrap5/app.py b/examples/bootstrap5/app.py index acb85b23..5e7441d5 100644 --- a/examples/bootstrap5/app.py +++ b/examples/bootstrap5/app.py @@ -287,6 +287,11 @@ def new_message(): return 'Here is the new message page. Return to table.' +@app.route('/image') +def test_image(): + return render_template('image.html') + + @app.route('/icon') def test_icon(): return render_template('icon.html') diff --git a/examples/bootstrap5/static/rectangle-256x64.png b/examples/bootstrap5/static/rectangle-256x64.png new file mode 100644 index 00000000..5a2763de Binary files /dev/null and b/examples/bootstrap5/static/rectangle-256x64.png differ diff --git a/examples/bootstrap5/static/rectangle-256x64.svg b/examples/bootstrap5/static/rectangle-256x64.svg new file mode 100644 index 00000000..ea2403f0 --- /dev/null +++ b/examples/bootstrap5/static/rectangle-256x64.svg @@ -0,0 +1,63 @@ + + + + + + + + + 256 × 64 px + + diff --git a/examples/bootstrap5/templates/image.html b/examples/bootstrap5/templates/image.html new file mode 100644 index 00000000..6d7ca7b2 --- /dev/null +++ b/examples/bootstrap5/templates/image.html @@ -0,0 +1,31 @@ +{% extends 'base.html' %} +{% from 'bootstrap5/utils.html' import render_image %} + +{% block content %} +

Image

+
{% raw %}{{ render_image(url_for('static', filename='rectangle-256x64.png'), alt='url_for') }}{% endraw %}
+Output: {{ render_image(url_for('static', filename='rectangle-256x64.png'), alt='url_for') }} + +

Thumbnail

+
{% raw %}{{ render_image('static/rectangle-256x64.png', alt='thumb', corner='thumbnail') }}{% endraw %}
+Output: {{ render_image('static/rectangle-256x64.png', alt='thumb', corner='thumbnail') }} + +

Image fluid

+
{% raw %}{{ render_image('static/rectangle-256x64.png', alt='fluid', fluid=True) }}{% endraw %}
+Output: {{ render_image('static/rectangle-256x64.png', alt='fluid', fluid=True) }} + +

Centered image

+
{% raw %}{{ render_image('static/rectangle-256x64.png', alt='center', center=True) }}{% endraw %}
+Output: {{ render_image('static/rectangle-256x64.png', alt='center', center=True) }} +
{% raw %}{{ render_image('static/rectangle-256x64.png', alt='mx-auto', mx_auto=True) }}{% endraw %}
+Output: {{ render_image('static/rectangle-256x64.png', alt='mx-auto', mx_auto=True) }} + +

Rounded image

+
{% raw %}{{ render_image('static/rectangle-256x64.png', alt='rounded', corner='rounded') }}{% endraw %}
+Output: {{ render_image('static/rectangle-256x64.png', alt='rounded', corner='rounded') }} + +

Float image

+
{% raw %}{{ render_image('static/rectangle-256x64.png', alt='float-start', float='start') }}
+{{ render_image('static/rectangle-256x64.png', alt='float-end', float='end') }}{% endraw %}
+Output: {{ render_image('static/rectangle-256x64.png', alt='float-start', float='start') }}{{ render_image('static/rectangle-256x64.png', alt='float-end', float='end') }} +{% endblock %} diff --git a/examples/bootstrap5/templates/index.html b/examples/bootstrap5/templates/index.html index f179ed36..2be8d0bc 100644 --- a/examples/bootstrap5/templates/index.html +++ b/examples/bootstrap5/templates/index.html @@ -10,6 +10,7 @@

Bootstrap-Flask Demo Application

  • Pagination
  • Flash Messages
  • Table
  • +
  • Image
  • Icon
  • Icons
  • diff --git a/flask_bootstrap/templates/bootstrap5/utils.html b/flask_bootstrap/templates/bootstrap5/utils.html index 98aab6bf..bb05591f 100644 --- a/flask_bootstrap/templates/bootstrap5/utils.html +++ b/flask_bootstrap/templates/bootstrap5/utils.html @@ -38,3 +38,22 @@ {% endif -%} {% endwith -%} {% endmacro -%} + + +{% macro render_image(src, alt, fluid=False, corner=None, center=False, + float=None, mx_auto=None) -%} + {%- if center -%} +
    + {%- endif -%} + {{ alt }} + {%- if center -%} +
    + {%- endif -%} +{%- endmacro -%}