svgo vs imagemin-svgo vs gulp-svgmin
SVG Optimization Tools Comparison
1 Year
svgoimagemin-svgogulp-svgminSimilar Packages:
What's SVG Optimization Tools?

SVG optimization tools are essential in web development for reducing the file size of SVG images without sacrificing quality. These tools help streamline the SVG files by removing unnecessary metadata, reducing precision, and optimizing paths, which ultimately improves load times and performance for web applications. By using these tools, developers can ensure that their SVG assets are lightweight and efficient, leading to a better user experience and faster rendering times in browsers.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
svgo19,180,69621,4981.49 MB248a year agoMIT
imagemin-svgo574,0631292.91 kB310 months agoMIT
gulp-svgmin55,252340-74 years agoMIT
Feature Comparison: svgo vs imagemin-svgo vs gulp-svgmin

Integration

  • svgo:

    svgo operates as a standalone tool, which means it can be used independently of any build system. This flexibility allows developers to optimize SVG files directly from the command line or integrate it into custom workflows without being tied to a specific task runner.

  • imagemin-svgo:

    imagemin-svgo is designed to work within the Imagemin ecosystem, which is a widely used image optimization framework. This integration allows for a unified approach to handling various image formats, making it suitable for projects that require multi-format image optimization.

  • gulp-svgmin:

    gulp-svgmin integrates seamlessly with Gulp, allowing developers to easily add SVG optimization to their build processes. It can be combined with other Gulp plugins to create a comprehensive asset pipeline, making it ideal for projects that rely heavily on Gulp for task automation.

Customization

  • svgo:

    svgo provides an extensive set of configuration options that can be tailored to meet specific optimization needs. Users can enable or disable various optimization plugins, giving them complete control over the optimization process and allowing for highly customized SVG outputs.

  • imagemin-svgo:

    imagemin-svgo offers a range of customizable options through its plugin architecture, allowing users to fine-tune the optimization process according to their needs. This is particularly useful for projects that require different optimization strategies for different SVG assets.

  • gulp-svgmin:

    gulp-svgmin allows for customization through Gulp's configuration options, enabling developers to set specific optimization parameters and choose which optimizations to apply. This level of control is beneficial for projects with unique SVG requirements.

Performance

  • svgo:

    svgo is designed for high performance in standalone usage, focusing solely on SVG optimization. It efficiently processes SVG files, making it suitable for projects that prioritize speed and require quick optimizations without the overhead of a build system.

  • imagemin-svgo:

    imagemin-svgo benefits from Imagemin's performance optimizations, allowing for fast processing of SVG files alongside other image formats. This is advantageous for projects that require batch processing of various image types, ensuring quick and efficient optimization.

  • gulp-svgmin:

    gulp-svgmin is optimized for performance within Gulp's task runner, allowing for efficient processing of multiple SVG files in a single build step. This can significantly reduce build times in larger projects with numerous SVG assets.

Ease of Use

  • svgo:

    svgo is straightforward to use as a command-line tool, making it accessible for developers who prefer a simple, no-frills approach to SVG optimization. Its extensive documentation aids in understanding its capabilities and configuration.

  • imagemin-svgo:

    imagemin-svgo is easy to use for those already familiar with Imagemin, allowing for quick integration into projects. Its plugin-based approach makes it intuitive for developers who need to optimize multiple image formats.

  • gulp-svgmin:

    gulp-svgmin is user-friendly for those familiar with Gulp, providing a straightforward API for integrating SVG optimization into existing workflows. However, it may have a learning curve for developers new to Gulp.

Community and Support

  • svgo:

    svgo has a dedicated community and is widely used in various projects, ensuring that developers can find ample resources, tutorials, and support. Its popularity also means that it is regularly updated with new features and optimizations.

  • imagemin-svgo:

    imagemin-svgo is part of the Imagemin ecosystem, which has a strong community and extensive documentation. This support network helps developers troubleshoot issues and optimize their image processing workflows effectively.

  • gulp-svgmin:

    gulp-svgmin benefits from the large Gulp community, providing access to numerous resources, plugins, and community support. This makes it easier for developers to find solutions and best practices for SVG optimization within Gulp.

How to Choose: svgo vs imagemin-svgo vs gulp-svgmin
  • svgo:

    Choose svgo if you need a standalone command-line tool or library specifically for SVG optimization without the overhead of a build system. It offers extensive configuration options and is suitable for developers who want fine-grained control over the optimization process.

  • imagemin-svgo:

    Choose imagemin-svgo if you are using the Imagemin framework for image optimization and want to specifically target SVG files. It provides a plugin-based architecture, allowing you to combine it with other image optimization plugins, making it ideal for projects that require comprehensive image handling.

  • gulp-svgmin:

    Choose gulp-svgmin if you are already using Gulp as your build tool and want to integrate SVG optimization into your existing Gulp workflow. It allows for easy configuration and chaining with other Gulp tasks, making it suitable for projects that require a streamlined build process.

README for svgo

SVGO npm chat docs

SVGO, short for SVG Optimizer, is a Node.js library and command-line application for optimizing SVG files.

Why?

SVG files, especially those exported from vector editors, usually contain a lot of redundant information. This includes editor metadata, comments, hidden elements, default or suboptimal values, and other stuff that can be safely removed or converted without impacting rendering.

Installation

You can install SVGO globally through npm, yarn, or pnpm. Alternatively, drop the global flag (global/-g) to use it in your Node.js project.

# npm
npm install -g svgo

# yarn
yarn global add svgo

# pnpm
pnpm add -g svgo

Command-line usage

Process single files:

svgo one.svg two.svg -o one.min.svg two.min.svg

Process a directory of files recursively with -f/--folder:

svgo -f path/to/directory_with_svgs -o path/to/output_directory

Help for advanced usage:

svgo --help

Configuration

SVGO has a plugin architecture. You can read more about all plugins in Plugins | SVGO Documentation, and the default plugins in Preset Default | SVGO Documentation.

SVGO reads the configuration from svgo.config.js or the --config path/to/config.js command-line option. Some other parameters can be configured though command-line options too.

svgo.config.js

module.exports = {
  multipass: false, // boolean
  datauri: 'base64', // 'base64'|'enc'|'unenc'
  js2svg: {
    indent: 4, // number
    pretty: false, // boolean
  },
  plugins: [
    'preset-default', // built-in plugins enabled by default
    'prefixIds', // enable built-in plugins by name

    // enable built-in plugins with an object to configure plugins
    {
      name: 'prefixIds',
      params: {
        prefix: 'uwu',
      },
    },
  ],
};

Default preset

Instead of configuring SVGO from scratch, you can tweak the default preset to suit your needs by configuring or disabling the respective plugin.

svgo.config.js

module.exports = {
  plugins: [
    {
      name: 'preset-default',
      params: {
        overrides: {
          // disable a default plugin
          removeViewBox: false,

          // customize the params of a default plugin
          inlineStyles: {
            onlyMatchedOnce: false,
          },
        },
      },
    },
  ],
};

You can find a list of the default plugins in the order they run in Preset Default | SVGO Documentation.

Custom plugins

You can also specify custom plugins:

svgo.config.js

const importedPlugin = require('./imported-plugin');

module.exports = {
  plugins: [
    // plugin imported from another JavaScript file
    importedPlugin,

    // plugin defined inline
    {
      name: 'customPlugin',
      params: {
        paramName: 'paramValue',
      },
      fn: (ast, params, info) => {},
    },
  ],
};

API usage

SVGO provides a few low level utilities.

optimize

The core of SVGO is optimize function.

const { optimize } = require('svgo');

const result = optimize(svgString, {
  path: 'path-to.svg', // recommended
  multipass: true, // all other config fields are available here
});

const optimizedSvgString = result.data;

loadConfig

If you write a tool on top of SVGO you may want to resolve the svgo.config.js file.

const { loadConfig } = require('svgo');

const config = await loadConfig();

You can also specify a path and customize the current working directory.

const config = await loadConfig(configFile, cwd);

Other ways to use SVGO

| Method | Reference | | ------------------------- | ----------------------------------------------------------------------------------------------------------------------- | | Web app | SVGOMG | | Grunt task | grunt-svgmin | | Gulp task | gulp-svgmin | | Webpack loader | image-minimizer-webpack-plugin | | PostCSS plugin | postcss-svgo | | Inkscape plugin | inkscape-svgo | | Sketch plugin | svgo-compressor | | Rollup plugin | rollup-plugin-svgo | | Visual Studio Code plugin | vscode-svgo | | Atom plugin | atom-svgo | | Sublime plugin | Sublime-svgo | | Figma plugin | Advanced SVG Export | | Linux app | Oh My SVG | | Browser extension | SVG Gobbler | | API | Vector Express |

Donors

| | | | :------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------: | | SheetJS LLC | Fontello |

License and Copyright

This software is released under the terms of the MIT license.

Logo by André Castillo.