Giter Club home page Giter Club logo

metalsmith-convert's Introduction

metalsmith-convert

This is a plugin for Metalsmith that uses node-imagemagick-native to convert image-files

Continuous testing courtesy of travis-ci:

Build Status

Installation

This module is released via npm, install the latest released version with

npm install --save metalsmith-convert

Dependencies

This module uses node-imagemagick-native. You must be able to compile c++ code to install imagemagick-native. The Readme provides instructions for Linux, Mac OS X and Windows respectively.

Usage

If using the CLI for Metalsmith, metalsmith-convert can be used like any other plugin by including it in metalsmith.json. For example:

{
  "plugins": {
    "metalsmith-convert": {
      "src": "**/*.svn",
      "target": "png"
    }
  }
}

For metalsmiths JavaScript API, metalsmith-convert can be used like any other plugin, by attaching it to the function invocation chain on the metalscript object. For example:

var copy = require('metalsmith-convert');
require('metalsmith')(__dirname)
  .use(convert({
    src: '**/*.svg',
    target: 'png'
  })
  .build();

Options

metalsmith-convert requires a src and target options.

  • src is a globbing pattern that specifies which files to convert
  • target is an imagemagick format specifier
  • extension the file extension to use for the conversion target (starting with .). Set to "." + target if not given explicitly.
  • remove if set to true, don't include the source-file in the build directory.
  • resize set to {width: XXX, height: YYY} to resize the image; the name will reflect the size (name_XXX_YYY.ext) if nameFormat is not given.
  • nameFormat give the format for the names of the converted files, the following placeholders are available
    • %b the basename of the source file, e.g. given source.png, the value will be source
    • %e the extension of the target format, including the dot
    • %x the width of the resulting image
    • %y the height if the resulting image

It is possible to pass options as array of option-objects to implement multiple rules, e.g. resize to two sizes for different thumbnail sizes:

{
  "plugins": {
    "metalsmith-convert": [
      {
        "src": "**/*.svg",
        "target": "png",
        "resize": {width: 320, height: 240},
        "nameFormat": "%b_thumb%e"
      },
      {
        "src": "**/*.svg",
        "target": "png",
        "resize": {width: 640, height: 480},
        "nameFormat": "%b_thumb_large%e"
      }
    ]
  }
}

metalsmith-convert's People

Contributors

tomterl avatar

Watchers

Clément Renaud avatar James Cloos avatar

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.