Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Eleventy transform plugin to automatically optimize image output #208

Closed
zachleat opened this issue Feb 9, 2024 · 3 comments
Closed
Labels
enhancement New feature or request

Comments

@zachleat
Copy link
Member

zachleat commented Feb 9, 2024

This would alleviate any need for asynchronous/synchronous shortcodes and wouldn’t require any need for markdown plugins et al.

Reuse the transform methods for the HTML <base> plugin and the InputPath to URL plugins.

https://www.11ty.dev/docs/plugins/inputpath-to-url/
https://www.11ty.dev/docs/plugins/html-base/

Related to 11ty/eleventy#3194

@zachleat zachleat added the enhancement New feature or request label Feb 9, 2024
@zachleat
Copy link
Member Author

zachleat commented Feb 9, 2024

@zachleat zachleat added this to the Eleventy Image v3.2.0 milestone Feb 10, 2024
@zachleat
Copy link
Member Author

This feature will require @11ty/eleventy@3.0.0-alpha.5 or newer.

You can get finer grained control over the images by adding HTML attributes:

  • <img eleventy:ignore>: skips processing an image.
  • <img eleventy:formats>: override the default formats.
  • <img eleventy:widths>: override the default widths.
  • <img eleventy:output>: override the output directory (absolute paths are relative to the Eleventy output directory, relative paths are relative to the template’s URL).

Opt-in to this plugin via:

import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";

export default function(eleventyConfig) {
	eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
		// which file extensions to process
		extensions: "html",
		// optional, output image formats
		formats: ["avif", "webp", "auto"],
		// optional, output image widths
		// widths: ["auto"],

		// optional, attributes assigned on <img> override these values.
		defaultAttributes: {
			loading: "lazy",
			decoding: "async"
		}
	});
};

@zachleat zachleat changed the title Add transform method to automatically optimize image output Add Eleventy transform plugin to automatically optimize image output Feb 10, 2024
zachleat added a commit that referenced this issue Feb 10, 2024
@zachleat
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant