Giter Site home page Giter Site logo

metalsmith-image-dimensions's Introduction

No longer maintained

This is no longer maintained, code is archived and available for forking though.

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 imageDimensions = require('metalsmith-image-dimensions');

metalsmith
  .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 readImageSizes = require('metalsmith-image-dimensions/read_image_sizes');
const imageDimensionsTransform = require('metalsmith-image-dimensions/transform');

metalsmith
  .use(readImageSizes({
    path: '**/*.+(jpg|png)'
  }))
  .use(domTransform({
    transforms: [
      imageDimensionsTransform(options),
      // Your other transforms go here
    ]
  }));

Note that you must separately use readImageSizes before running the domTransform.

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).
  • path: minimatch case-insensitive glob that determines which files get processed (default: **/*.+(gif|jpg|png))
  • overwrite: Write width and height tags even if already set (default false)

Changelog

  • 0.1.0: Remove requirement for metalsmith-media-metadata and expose readImageSizes
  • 0.0.2: Fix bug where paths were not correctly resolved
  • 0.0.1: First release

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.