{ "info": { "author": "Canonical webteam", "author_email": "webteam@canonical.com", "bugtrack_url": null, "classifiers": [], "description": "# canonicalwebteam.image-template\n\nA module to generate performant HTML image markup for images. The markup\nwill:\n\n- Use [native lazyloading](https://addyosmani.com/blog/lazy-loading/) if it's available\n- Output markup compatible with [lazysizes `noscript` plugin](https://github.com/aFarkas/lazysizes/tree/gh-pages/plugins/noscript)\n- Explicitly define `width` and `height` attributes to avoid the page jumping effect\n- Prefix all image URLs with cloudinary CDN proxy URLs, to transform the image to the optimal size\n- Use predefined (2x) `srcset` break points for hidef screens\n\n## Parameters\n\n- `url` (mandatory string): The url to an image (e.g. `https://assets.ubuntu.com/v1/9f6916dd-k8s-prometheus-light.png`)\n- `alt` (mandatory string): Alt text to describe the image\n- `width` (mandatory integer): The number of pixels wide the image should be\n- `height` (mandatory integer): The number of pixels high the image should be\n- `hi_def` (mandatory boolean): Has an image been uploaded 2x the width and height of the desired size\n- `loading` (optional string, default: \"lazy\"): Set to [\"auto\" or \"eager\"](https://addyosmani.com/blog/lazy-loading/) to disable lazyloading\n- `attrs` (optional dictionary): Extra `` attributes (e.g. `class` or `id`) can be passed as additional arguments\n\n## Usage\n\nThe `image_template` function can be used directly to generate image Markup.\n\n``` python3\nfrom canonicalwebteam import image_template\n\nimage_markup = image_template(\n url=\"https://assets.ubuntu.com/v1/450d7c2f-openstack-hero.svg\",\n alt=\"\",\n width=\"534\",\n height=\"319\",\n hi_def=True,\n loading=\"auto\",\n attrs={\"class\": \"hero\", \"id\": \"openstack-hero\"},\n)\n```\n\nHowever, the most common usage is to add it to Django or Flask template contexts, as an `image` function.\n\n### Add lazysizes\n\nAt the time of writing, the `loading` attribute [is only natively supported](https://caniuse.com/#search=loading) in Chrome. Therefore we use [lazysizes](https://github.com/aFarkas/lazysizes) to enable loading in other browsers while still taking advantage of the native functionality when it's available.\n\nIf `loading` is set to \"lazy\" (the default) we will output [the Markup](#generated-markup) in a format supported by [lazysizes](https://github.com/aFarkas/lazysizes), with the [`noscript`](https://github.com/aFarkas/lazysizes/tree/gh-pages/plugins/noscript) and [`native-loading`](https://github.com/aFarkas/lazysizes/tree/gh-pages/plugins/native-loading) plugins enabled.\n\nTo support this in your site you need to add the following script to the `` of each page, *above* any `` attributes:\n\n``` html\n\n```\n\n### Django usage\n\nAdd it as a template tag:\n\n``` python3\n# myapp/templatetags.py\n\nfrom canonicalwebteam import image_template\nfrom django import template\nfrom django.utils.safestring import mark_safe\n\n\nregister = template.Library()\n\n@register.simple_tag\ndef image(*args, **kwargs):\n return mark_safe(image_template(*args, **kwargs))\n\n\n# settings.py\n\nTEMPLATES[0][\"OPTIONS\"][\"builtins\"].append(\"myapp.templatetags\")\n```\n\nUse it in templates:\n\n``` html\n# templates/mytemplate.html\n\n{% image url=\"https://assets.ubuntu.com/v1/9f6916dd-k8s-prometheus-light.png\" alt=\"Operational dashboard\" width=\"1040\" height=\"585\" hi_def=True %}\n```\n\n### Flask usage\n\nAdd it as a template tag:\n\n``` python3\n# app.py\n\nfrom canonicalwebteam import image_template\nfrom flask import Flask\n\napp = Flask(__name__)\n\n@app.context_processor\ndef utility_processor():\n return {\"image\": image_template}\n```\n\nUse it in templates, e.g.::\n\n``` html\n# templates/mytemplate.html\n\n{{\n image(\n url=\"https://assets.ubuntu.com/v1/450d7c2f-openstack-hero.svg\",\n alt=\"\",\n width=\"534\",\n height=\"319\",\n hi_def=True,\n loading=\"auto\",\n attrs={\"class\": \"hero\", \"id\": \"openstack-hero\"},\n ) | safe\n}}\n```\n\n## Generated markup\n\nThe output image markup will be e.g.:\n\n``` html\n\n```\n\nIf `loading` is set to \"lazy\" (the default), the output markup will be wrapped in markup for lazysizes support:\n\n``` html\n
\n \n
\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/canonical-web-and-design/canonicalwebteam.image-template", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "canonicalwebteam.image-template", "package_url": "https://pypi.org/project/canonicalwebteam.image-template/", "platform": "", "project_url": "https://pypi.org/project/canonicalwebteam.image-template/", "project_urls": { "Homepage": "https://github.com/canonical-web-and-design/canonicalwebteam.image-template" }, "release_url": "https://pypi.org/project/canonicalwebteam.image-template/1.0.0/", "requires_dist": null, "requires_python": "", "summary": "Generate markup block for an image.", "version": "1.0.0" }, "last_serial": 5949141, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "b5b6e73044103cecf5f7c52d892e00ba", "sha256": "518668d62b9d7c49e72d83f613bfa618385c2b795724ed07b2332e4b25989e2a" }, "downloads": -1, "filename": "canonicalwebteam.image-template-0.1.0.tar.gz", "has_sig": false, "md5_digest": "b5b6e73044103cecf5f7c52d892e00ba", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3530, "upload_time": "2019-02-26T09:05:29", "url": "https://files.pythonhosted.org/packages/86/19/b92a866dcfec8827e7bd8e696861a89660f3c37982b43fe7a1374b4cd72e/canonicalwebteam.image-template-0.1.0.tar.gz" } ], "0.1.0a0": [ { "comment_text": "", "digests": { "md5": "a56e17e3fe3a4478f7c5b467d3d3a1d0", "sha256": "abe53acd3d7b65fc210e87324a3f2348de7b88cd59540365206bac7ec5d6aeb6" }, "downloads": -1, "filename": "canonicalwebteam.image-template-0.1.0a0.tar.gz", "has_sig": false, "md5_digest": "a56e17e3fe3a4478f7c5b467d3d3a1d0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1466, "upload_time": "2019-02-25T13:53:51", "url": "https://files.pythonhosted.org/packages/7b/c7/40af0c1f40901ee0a905bdf70e0f62942702181c43a7baaeecbea3b67964/canonicalwebteam.image-template-0.1.0a0.tar.gz" } ], "0.1.0a2": [ { "comment_text": "", "digests": { "md5": "714b70c79938253c2732c4f1f1e11bbc", "sha256": "d47114c9dcc1e35894d5e218ba910ddbbe416402767f8fdf2af364c6099a6060" }, "downloads": -1, "filename": "canonicalwebteam.image-template-0.1.0a2.tar.gz", "has_sig": false, "md5_digest": "714b70c79938253c2732c4f1f1e11bbc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2562, "upload_time": "2019-02-25T15:38:17", "url": "https://files.pythonhosted.org/packages/4c/c7/c1baf557f11e218f65238c10208b99edaa6089ccb8ed69a5c33dfbf363e5/canonicalwebteam.image-template-0.1.0a2.tar.gz" } ], "0.1.0a3": [ { "comment_text": "", "digests": { "md5": "ec2024422fbcfeb287aa365740d286bb", "sha256": "fc5af069a5875f23b1ec5df074ef5c52ef2b576fa3c816cbcec3e29ebe325c0e" }, "downloads": -1, "filename": "canonicalwebteam.image-template-0.1.0a3.tar.gz", "has_sig": false, "md5_digest": "ec2024422fbcfeb287aa365740d286bb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2783, "upload_time": "2019-02-25T15:53:58", "url": "https://files.pythonhosted.org/packages/1a/33/e3591167f39bca7f8536d08ebdf2024d8d163104cf7c9373cf1850c6e91a/canonicalwebteam.image-template-0.1.0a3.tar.gz" } ], "0.1.0a4": [ { "comment_text": "", "digests": { "md5": "e94e41381440e7617a1b95f45c0105e8", "sha256": "e9ab4a1e0753d37ec24a3ac3625501781c64278e9975cdb0ac5aeabe6340e15a" }, "downloads": -1, "filename": "canonicalwebteam.image-template-0.1.0a4.tar.gz", "has_sig": false, "md5_digest": "e94e41381440e7617a1b95f45c0105e8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2790, "upload_time": "2019-02-25T15:58:18", "url": "https://files.pythonhosted.org/packages/02/e2/62066831bf6f502c1e34167d15ed9a96adfcf813a0860a2f7ac177f86a75/canonicalwebteam.image-template-0.1.0a4.tar.gz" } ], "0.1.0a5": [ { "comment_text": "", "digests": { "md5": "27283fcd1ff6f4112342afc7a459d4ef", "sha256": "b66d040ea9be03b736231f979213653dc5b29347bc71c29a23c1632406d7adf5" }, "downloads": -1, "filename": "canonicalwebteam.image-template-0.1.0a5.tar.gz", "has_sig": false, "md5_digest": "27283fcd1ff6f4112342afc7a459d4ef", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2798, "upload_time": "2019-02-25T16:00:52", "url": "https://files.pythonhosted.org/packages/94/5e/4b5347345bbe9bedaa7360bbfd1830b66a6c3f66ea970cb409f84a0dc6ac/canonicalwebteam.image-template-0.1.0a5.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "d31626fdbbd0433c47e70a3ed34c3bfd", "sha256": "3b2b03cbb38457c09573c76411a21c69eface39d5cf450f628a645c05746e14b" }, "downloads": -1, "filename": "canonicalwebteam.image-template-0.2.0.tar.gz", "has_sig": false, "md5_digest": "d31626fdbbd0433c47e70a3ed34c3bfd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4078, "upload_time": "2019-02-28T11:02:07", "url": "https://files.pythonhosted.org/packages/73/80/dec846d8f6e2280e46ad9f027572ec1bfd4c630d6612d4f0615b7a748a3c/canonicalwebteam.image-template-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "fb14260c02872001d9a7bb2fbc54296f", "sha256": "e96f5c443e71795d7b70f0a05b9f258e67ee334f0383b0b42193c0212a9caddd" }, "downloads": -1, "filename": "canonicalwebteam.image-template-0.2.1.tar.gz", "has_sig": false, "md5_digest": "fb14260c02872001d9a7bb2fbc54296f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4174, "upload_time": "2019-03-01T11:21:53", "url": "https://files.pythonhosted.org/packages/a0/3c/c34a6f8c7cd8a3a86ca41cb73c280af5e414c780b8e61f3c6757b1534246/canonicalwebteam.image-template-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "1691da52b5dc2e7369bfd0004d3d8c2a", "sha256": "6048e4c930d8a69f3dbe59a49ac1cd1e44e316dd909947281c157131006b7d0d" }, "downloads": -1, "filename": "canonicalwebteam.image-template-0.2.2.tar.gz", "has_sig": false, "md5_digest": "1691da52b5dc2e7369bfd0004d3d8c2a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4189, "upload_time": "2019-03-01T12:16:30", "url": "https://files.pythonhosted.org/packages/09/10/b86bc9cf1e9acf0561366a3c3de44774892bf9a63bee42c2adaafb1dc0ca/canonicalwebteam.image-template-0.2.2.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "4f8f40110b12ebfc8b8d6cc45dce6c3e", "sha256": "2977d19596b8f29101eed1d32a93f420f3a4a834eaf667dca524e0ef4dde91c7" }, "downloads": -1, "filename": "canonicalwebteam.image-template-0.2.3.tar.gz", "has_sig": false, "md5_digest": "4f8f40110b12ebfc8b8d6cc45dce6c3e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4175, "upload_time": "2019-03-01T12:32:50", "url": "https://files.pythonhosted.org/packages/7c/6c/a45bf8b1f163150bfb000945f89e88105966476637e1608a35ccac04019a/canonicalwebteam.image-template-0.2.3.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "01543bb9d2ef2b824af955c89c2faa6e", "sha256": "49c746bb4bccc7ff8d6e67e4563b484486d737108d4690cde0d70ad6ce8fbce9" }, "downloads": -1, "filename": "canonicalwebteam.image-template-0.3.0.tar.gz", "has_sig": false, "md5_digest": "01543bb9d2ef2b824af955c89c2faa6e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4146, "upload_time": "2019-08-20T14:49:23", "url": "https://files.pythonhosted.org/packages/bf/c9/56c61f923d2325eb3b1d0f96ac6488f109007c309268faf5364dfb462409/canonicalwebteam.image-template-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "4854247a4cd5a7a8c02e026a125f4ef4", "sha256": "99de4967c15a0370b9ce74a6f27b061ff505ec3af4878ddb576a708b01cb9867" }, "downloads": -1, "filename": "canonicalwebteam.image-template-0.3.1.tar.gz", "has_sig": false, "md5_digest": "4854247a4cd5a7a8c02e026a125f4ef4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4157, "upload_time": "2019-09-30T15:12:56", "url": "https://files.pythonhosted.org/packages/a9/19/9a16bf10573fb33719db7666a67194e10baf196cd03892f43494309b0323/canonicalwebteam.image-template-0.3.1.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "2bc48562d6e68dad03d96b9e381e411f", "sha256": "a716cff11331ae5eb86483d6dea0eb6c7bd4c990a5563b70bc1bed3c36ef9789" }, "downloads": -1, "filename": "canonicalwebteam.image-template-1.0.0.tar.gz", "has_sig": false, "md5_digest": "2bc48562d6e68dad03d96b9e381e411f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4124, "upload_time": "2019-10-09T11:08:46", "url": "https://files.pythonhosted.org/packages/1f/33/05b73ca2ccca1a664893dd94af123162c741e1db005b221a7ae49d974996/canonicalwebteam.image-template-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2bc48562d6e68dad03d96b9e381e411f", "sha256": "a716cff11331ae5eb86483d6dea0eb6c7bd4c990a5563b70bc1bed3c36ef9789" }, "downloads": -1, "filename": "canonicalwebteam.image-template-1.0.0.tar.gz", "has_sig": false, "md5_digest": "2bc48562d6e68dad03d96b9e381e411f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4124, "upload_time": "2019-10-09T11:08:46", "url": "https://files.pythonhosted.org/packages/1f/33/05b73ca2ccca1a664893dd94af123162c741e1db005b221a7ae49d974996/canonicalwebteam.image-template-1.0.0.tar.gz" } ] }