favicons
Favicon generator for Node.js
Last updated 3 years ago by andy128k .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install favicons 
SYNC missed versions from official npm registry.

Favicons

NPM version Build Status Coverage Status Dependencies Status DevDependencies Status Greenkeeper badge

A Node.js module for generating favicons and their associated files. Originally built for Google's Web Starter Kit and Catalyst. Requires Node 4+. Installed through NPM with:

npm install favicons

Usage

Node.js

To use Favicons, require the appropriate module and call it, optionally specifying configuration and callback objects. A sample is shown on the right. The full list of options can be found on GitHub.

The Gulp / Grunt wrapper modules have a few extra properties. You can also configure and use Favicons from the terminal with dot syntax.

Favicons generates its icons locally using pure Javascript with no external dependencies.

Please note: Favicons is tested on Node 10.13 and above.

var favicons = require("favicons"),
  source = "test/logo.png", // Source image(s). `string`, `buffer` or array of `string`
  configuration = {
    path: "/", // Path for overriding default icons path. `string`
    appName: null, // Your application's name. `string`
    appShortName: null, // Your application's short_name. `string`. Optional. If not set, appName will be used
    appDescription: null, // Your application's description. `string`
    developerName: null, // Your (or your developer's) name. `string`
    developerURL: null, // Your (or your developer's) URL. `string`
    dir: "auto", // Primary text direction for name, short_name, and description
    lang: "en-US", // Primary language for name and short_name
    background: "#fff", // Background colour for flattened icons. `string`
    theme_color: "#fff", // Theme color user for example in Android's task switcher. `string`
    appleStatusBarStyle: "black-translucent", // Style for Apple status bar: "black-translucent", "default", "black". `string`
    display: "standalone", // Preferred display mode: "fullscreen", "standalone", "minimal-ui" or "browser". `string`
    orientation: "any", // Default orientation: "any", "natural", "portrait" or "landscape". `string`
    scope: "/", // set of URLs that the browser considers within your app
    start_url: "/?homescreen=1", // Start URL when launching the application from a device. `string`
    preferRelatedApplications: false, // Should the browser prompt the user to install the native companion app. `boolean`
    relatedApplications: undefined, // Information about the native companion apps. This will only be used if `preferRelatedApplications` is `true`. `Array<{ id: string, url: string, platform: string }>`
    version: "1.0", // Your application's version string. `string`
    logging: false, // Print logs to console? `boolean`
    pixel_art: false, // Keeps pixels "sharp" when scaling up, for pixel art.  Only supported in offline mode.
    loadManifestWithCredentials: false, // Browsers don't send cookies when fetching a manifest, enable this to fix that. `boolean`
    manifestMaskable: false, // Maskable source image(s) for manifest.json. "true" to use default source. More information at https://web.dev/maskable-icon/. `boolean`, `string`, `buffer` or array of `string`
    icons: {
      // Platform Options:
      // - offset - offset in percentage
      // - background:
      //   * false - use default
      //   * true - force use default, e.g. set background for Android icons
      //   * color - set background for the specified icons
      //
      android: true, // Create Android homescreen icon. `boolean` or `{ offset, background }` or an array of sources
      appleIcon: true, // Create Apple touch icons. `boolean` or `{ offset, background }` or an array of sources
      appleStartup: true, // Create Apple startup images. `boolean` or `{ offset, background }` or an array of sources
      favicons: true, // Create regular favicons. `boolean` or `{ offset, background }` or an array of sources
      windows: true, // Create Windows 8 tile icons. `boolean` or `{ offset, background }` or an array of sources
      yandex: true, // Create Yandex browser icon. `boolean` or `{ offset, background }` or an array of sources
    },
  },
  callback = function (error, response) {
    if (error) {
      console.log(error.message); // Error description e.g. "An unknown error has occurred"
      return;
    }
    console.log(response.images); // Array of { name: string, contents: <buffer> }
    console.log(response.files); // Array of { name: string, contents: <string> }
    console.log(response.html); // Array of strings (html elements)
  };

favicons(source, configuration, callback);

The default sources are as follow (groupped by platform):

{
  "android": [
    "android-chrome-144x144.png",
    "android-chrome-192x192.png",
    "android-chrome-256x256.png",
    "android-chrome-36x36.png",
    "android-chrome-384x384.png",
    "android-chrome-48x48.png",
    "android-chrome-512x512.png",
    "android-chrome-72x72.png",
    "android-chrome-96x96.png"
  ],
  "appleIcon": [
    "apple-touch-icon-1024x1024.png",
    "apple-touch-icon-114x114.png",
    "apple-touch-icon-120x120.png",
    "apple-touch-icon-144x144.png",
    "apple-touch-icon-152x152.png",
    "apple-touch-icon-167x167.png",
    "apple-touch-icon-180x180.png",
    "apple-touch-icon-57x57.png",
    "apple-touch-icon-60x60.png",
    "apple-touch-icon-72x72.png",
    "apple-touch-icon-76x76.png",
    "apple-touch-icon-precomposed.png",
    "apple-touch-icon.png"
  ],
  "appleStartup": [
    "apple-touch-startup-image-1125x2436.png",
    "apple-touch-startup-image-1136x640.png",
    "apple-touch-startup-image-1242x2208.png",
    "apple-touch-startup-image-1242x2688.png",
    "apple-touch-startup-image-1334x750.png",
    "apple-touch-startup-image-1536x2048.png",
    "apple-touch-startup-image-1620x2160.png",
    "apple-touch-startup-image-1668x2224.png",
    "apple-touch-startup-image-1668x2388.png",
    "apple-touch-startup-image-1792x828.png",
    "apple-touch-startup-image-2048x1536.png",
    "apple-touch-startup-image-2048x2732.png",
    "apple-touch-startup-image-2160x1620.png",
    "apple-touch-startup-image-2208x1242.png",
    "apple-touch-startup-image-2224x1668.png",
    "apple-touch-startup-image-2388x1668.png",
    "apple-touch-startup-image-2436x1125.png",
    "apple-touch-startup-image-2688x1242.png",
    "apple-touch-startup-image-2732x2048.png",
    "apple-touch-startup-image-640x1136.png",
    "apple-touch-startup-image-750x1334.png",
    "apple-touch-startup-image-828x1792.png"
  ],
  "favicons": [
    "favicon-16x16.png",
    "favicon-32x32.png",
    "favicon-48x48.png",
    "favicon.ico"
  ],
  "windows": [
    "mstile-144x144.png",
    "mstile-150x150.png",
    "mstile-310x150.png",
    "mstile-310x310.png",
    "mstile-70x70.png"
  ],
  "yandex": [
    "yandex-browser-50x50.png"
  ]
}

You can programmatically access Favicons configuration (icon filenames, HTML, manifest files, etc) with:

var config = require("favicons").config;

Gulp

To use Favicons with Gulp, you can either use the gulp-plugin or call it manually as follows:

var favicons = require("favicons").stream,
  log = require("fancy-log");

gulp.task("default", function () {
  return gulp
    .src("logo.png")
    .pipe(
      favicons({
        appName: "My App",
        appShortName: "App",
        appDescription: "This is my application",
        developerName: "Hayden Bleasel",
        developerURL: "http://haydenbleasel.com/",
        background: "#020307",
        path: "favicons/",
        url: "http://haydenbleasel.com/",
        display: "standalone",
        orientation: "portrait",
        scope: "/",
        start_url: "/?homescreen=1",
        version: 1.0,
        logging: false,
        html: "index.html",
        pipeHTML: true,
        replace: true,
      })
    )
    .on("error", log)
    .pipe(gulp.dest("./"));
});

Output

For the full list of files, check config/files.json. For the full HTML code, check config/html.js. Finally, for the full list of icons, check config/icons.json.

Questions

Why are you missing certain favicons?

Because pure Javascript modules aren't available at the moment. For example, the El Capitan SVG favicon and the Windows tile silhouette ability both require SVG support. If modules for these task begin to appear, please jump on the appropriate issue and we'll get on it ASAP.

Thank you

Contribution

Feel free to push your code if you agree with publishing under the MIT license.

When testing, don't forget to update snapshots whenever you edit them: npm test -- -u.

License

Current Tags

  • 7.0.0-beta.1                                ...           beta (3 years ago)
  • 7.2.0                                ...           latest (8 months ago)

124 Versions

  • 7.2.0                                ...           8 months ago
  • 7.1.5                                ...           a year ago
  • 7.1.4                                ...           a year ago
  • 7.1.3                                ...           a year ago
  • 7.1.2                                ...           2 years ago
  • 7.1.1                                ...           2 years ago
  • 7.1.0                                ...           2 years ago
  • 7.0.2                                ...           2 years ago
  • 7.0.1                                ...           2 years ago
  • 7.0.0                                ...           2 years ago
  • 7.0.0-beta.5                                ...           2 years ago
  • 7.0.0-beta.4                                ...           3 years ago
  • 7.0.0-beta.3                                ...           3 years ago
  • 7.0.0-beta.2                                ...           3 years ago
  • 7.0.0-beta.1                                ...           3 years ago
  • 7.0.0-beta.0                                ...           3 years ago
  • 6.2.2                                ...           4 years ago
  • 6.2.1                                ...           4 years ago
  • 6.2.0                                ...           4 years ago
  • 6.1.0                                ...           4 years ago
  • 6.0.0                                ...           5 years ago
  • 5.5.0                                ...           5 years ago
  • 5.4.1                                ...           5 years ago
  • 5.4.0                                ...           5 years ago
  • 5.3.0                                ...           6 years ago
  • 5.2.0                                ...           6 years ago
  • 5.1.1                                ...           7 years ago
  • 5.1.0                                ...           7 years ago
  • 5.0.0                                ...           7 years ago
  • 4.8.6                                ...           8 years ago
  • 4.8.4                                ...           8 years ago
  • 4.8.3                                ...           8 years ago
  • 4.8.2                                ...           8 years ago
  • 4.8.1                                ...           8 years ago
  • 4.8.0                                ...           8 years ago
  • 4.7.8                                ...           8 years ago
  • 4.7.7                                ...           8 years ago
  • 4.7.6                                ...           8 years ago
  • 4.7.5                                ...           8 years ago
  • 4.7.4                                ...           8 years ago
  • 4.7.3                                ...           8 years ago
  • 4.7.2                                ...           8 years ago
  • 4.7.1                                ...           9 years ago
  • 4.7.0                                ...           9 years ago
  • 4.6.1                                ...           9 years ago
  • 4.6.0                                ...           9 years ago
  • 4.5.5                                ...           9 years ago
  • 4.5.4                                ...           9 years ago
  • 4.5.3                                ...           9 years ago
  • 4.5.2                                ...           9 years ago
  • 4.5.1                                ...           9 years ago
  • 4.5.0                                ...           9 years ago
  • 4.4.5                                ...           9 years ago
  • 4.4.4                                ...           9 years ago
  • 4.4.3                                ...           9 years ago
  • 4.4.2                                ...           9 years ago
  • 4.4.1                                ...           9 years ago
  • 4.4.0                                ...           9 years ago
  • 4.3.5                                ...           9 years ago
  • 4.3.4                                ...           9 years ago
  • 4.3.3                                ...           9 years ago
  • 4.3.2                                ...           9 years ago
  • 4.3.1                                ...           9 years ago
  • 4.3.0                                ...           9 years ago
  • 4.2.7                                ...           9 years ago
  • 4.2.6                                ...           9 years ago
  • 4.2.5                                ...           9 years ago
  • 4.2.3                                ...           9 years ago
  • 4.2.2                                ...           9 years ago
  • 4.2.0                                ...           9 years ago
  • 4.1.1                                ...           9 years ago
  • 4.1.0                                ...           9 years ago
  • 4.0.9                                ...           9 years ago
  • 4.0.8                                ...           9 years ago
  • 4.0.7                                ...           9 years ago
  • 4.0.6                                ...           9 years ago
  • 4.0.5                                ...           9 years ago
  • 4.0.4                                ...           9 years ago
  • 4.0.3                                ...           9 years ago
  • 4.0.2                                ...           9 years ago
  • 4.0.1                                ...           9 years ago
  • 4.0.0                                ...           9 years ago
  • 3.2.0                                ...           9 years ago
  • 3.1.3                                ...           9 years ago
  • 3.1.2                                ...           9 years ago
  • 3.1.1                                ...           10 years ago
  • 3.1.0                                ...           10 years ago
  • 3.0.2                                ...           10 years ago
  • 3.0.1                                ...           10 years ago
  • 3.0.0                                ...           10 years ago
  • 2.1.2                                ...           10 years ago
  • 2.1.1                                ...           10 years ago
  • 2.1.0                                ...           10 years ago
  • 2.0.8                                ...           10 years ago
  • 2.0.7                                ...           10 years ago
  • 2.0.6                                ...           10 years ago
  • 2.0.5                                ...           10 years ago
  • 2.0.4                                ...           10 years ago
  • 2.0.3                                ...           10 years ago
  • 2.0.2                                ...           10 years ago
  • 2.0.1                                ...           10 years ago
  • 2.0.0                                ...           10 years ago
  • 1.5.3                                ...           10 years ago
  • 1.5.2                                ...           10 years ago
  • 1.5.1                                ...           10 years ago
  • 1.4.4                                ...           10 years ago
  • 1.4.3                                ...           10 years ago
  • 1.4.2                                ...           10 years ago
  • 1.4.1                                ...           10 years ago
  • 1.4.0                                ...           10 years ago
  • 1.3.6                                ...           10 years ago
  • 1.3.5                                ...           10 years ago
  • 1.3.4                                ...           10 years ago
  • 1.3.3                                ...           10 years ago
  • 1.3.2                                ...           10 years ago
  • 1.3.1                                ...           10 years ago
  • 1.3.0                                ...           10 years ago
  • 1.2.7                                ...           10 years ago
  • 1.2.6                                ...           10 years ago
  • 1.2.5                                ...           10 years ago
  • 1.2.4                                ...           10 years ago
  • 1.2.3                                ...           10 years ago
  • 1.2.2                                ...           10 years ago
  • 1.2.1                                ...           10 years ago
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (7)
Dev Dependencies (17)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE