Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Metalsmith plugin for automatically adding width and height attributes to img tags

Notifications You must be signed in to change notification settings

fortes/metalsmith-image-dimensions

Repository files navigation

metalsmith-image-dimensions

build status codecov Greenkeeper badge

Metalsmith plugin for automatically adding width and height attributes to img tags.

Example

Input:

<img src="dog.jpg">

Output:

<img src="dog.jpg" width="100" height="50">

Usage

const mediaMetadata = require('metalsmith-media-metadata');
const imageDimensions = require('metalsmith-image-dimensions');

metalsmith
  .use(mediaMetadata())
  .use(imageDimensions({
    overwrite: true
  }));

Using with metalsmith-dom-transform

If you're already using metalsmith-dom-transform, you can save a little bit of overhead by accessing the image dimension transform directly:

const domTransform = require('metalsmith-image-dimensions');
const imageDimensionsTransform = require('metalsmith-image-dimensions/transform');

metalsmith.use(domTransform({
  transforms: [
    imageDimensionsTransform(options),
    // Your other transforms go here
  ]
}));

Requirements

Notes

  • External images are not supported since I didn't need them. File an issue if that's something you'd like.

Configuration

  • domain: Domain where this is hosted, used to determine if an image is external. It is unlikely that you'd need to set this, unless you have absolute URLs for image that are local to the site (default: http://example.com).
  • overwrite: Write width and height tags even if already set (default false)

Changelog

  • 0.0.1: First release

About

Metalsmith plugin for automatically adding width and height attributes to img tags

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published