{"id":19614347,"url":"https://github.com/fpapado/eleventy-img-example","last_synced_at":"2026-05-17T02:47:02.187Z","repository":{"id":96504854,"uuid":"328669213","full_name":"fpapado/eleventy-img-example","owner":"fpapado","description":"An example of using Eleventy's eleventy-img plugin","archived":false,"fork":false,"pushed_at":"2021-01-11T15:03:25.000Z","size":810,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-26T17:48:00.763Z","etag":null,"topics":["11ty","eleventy","image-processing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fpapado.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-11T13:15:33.000Z","updated_at":"2021-09-20T08:50:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"6e859710-b5b5-42ad-8889-92002ae6b5f7","html_url":"https://github.com/fpapado/eleventy-img-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fpapado/eleventy-img-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fpapado%2Feleventy-img-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fpapado%2Feleventy-img-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fpapado%2Feleventy-img-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fpapado%2Feleventy-img-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fpapado","download_url":"https://codeload.github.com/fpapado/eleventy-img-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fpapado%2Feleventy-img-example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264638002,"owners_count":23642091,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["11ty","eleventy","image-processing"],"created_at":"2024-11-11T10:51:29.886Z","updated_at":"2025-10-11T12:37:47.999Z","avatar_url":"https://github.com/fpapado.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 11ty-img-example\n\nAn example of using [Eleventy's eleventy-img plugin](https://www.11ty.dev/docs/plugins/image/).\n\n## Pre-requisites\n\nYou will need [Node](https://nodejs.org/en/download/) and npm installed. npm typically comes installed with node. I recommend [using a version manager, such as nvm, to manage your node installation](https://github.com/nvm-sh/nvm)\n\n## How to build\n\nIn a terminal, such as iTerm on MacOS, gnome terminal on Linux, or Windows Subsystem for Linux (WSL) on Windows, type:\n\nIf you have nvm installed, make sure the node versions match up\n\n```shell\nnvm use\n```\n\n```shell\n# Install dependencies\nnpm ci\n```\n\nIf the above command fails, try\n\n```shell\nnpm install\n```\n\nOnce the command completes, you are ready to build or develop!\n\nTo develop:\n\n```shell\nnpm run dev\n```\n\nThis will start a server at http://localhost:8080.\n\nTo build:\n\n```shell\nnpm run build\n```\n\nThis will build and output the final site under the `_site` directory. You can inspect the contents from there!\n\n## Where is eleventy-img used?\n\nThe eleventy-img package is used in `.eleventy.js`. It is used to create a shortcode called \"picture\", which is then used inside posts or templates.\n\nThe picture shortcode is [based on the eleventy-img example](https://www.11ty.dev/docs/plugins/image/#use-this-in-your-templates).\n\nThis is what the full shortcode looks like:\n\n```js\n/* Fetch and transform an image to a `picture` with multiple sources */\nasync function pictureShortcode(\nsrc,\nalt,\nsizes = \"\",\nloading = \"eager\",\ndecoding = \"auto\"\n) {\nlet metadata = await Image(src, {\n    // Set these however you like (the more widths, the more time to build, so not always a good idea to have a ton)\n    widths: [600, 1200, 1920],\n    // What formats to include. Avif and Webp are small, jpeg is supported more broadly. The browser will pick the right one\n    formats: [\"avif\", \"webp\", \"jpeg\"],\n    // Output images under _site/img/opt. This can help caching\n    outputDir: \"_site/img/opt/\",\n    // Inform the base path for URLs, e.g. in \u003csource\u003e and \u003cimg\u003e elements\n    urlPath: \"/img/opt/\",\n    // Rename 'box-on-table' to 'box-on-table-hashHere123-1200w.jpg' etc.\n    filenameFormat: function (id, src, width, format, options) {\n    const extension = path.extname(src);\n    const name = path.basename(src, extension);\n\n    return `${name}-${id}-${width}w.${format}`;\n    },\n});\n\nlet imageAttributes = {\n    alt,\n    sizes,\n    loading,\n    decoding,\n};\n\nreturn Image.generateHTML(metadata, imageAttributes, {\n    whitespaceMode: \"inline\",\n});\n}\n```\n\nAnd this is what usage (with Nunjucks templating) looks like:\n\n```njk\n# This is an example page\n\n{# Insert a picture element with different sources #}\n\n{% picture \"https://upload.wikimedia.org/wikipedia/commons/3/3b/Good_Morning_From_the_International_Space_Station.jpg\", \"The Earth at night, seen from the international space station. Cities and towns are lit up as bright spots.\", \"48rem\"  %}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffpapado%2Feleventy-img-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffpapado%2Feleventy-img-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffpapado%2Feleventy-img-example/lists"}