npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svg-app-icon

v2.0.0

Published

create high-quality desktop app icons for Windows, MacOS, and Linux using an SVG source

Downloads

360

Readme

svg app icon

🎨 Create high-quality desktop app icons for Windows, MacOS, and Linux using an SVG source

CI npm-downloads npm-version

📥 Install

npm install svg-app-icon

👨‍💻 API

const path = require('path');
const { promises: fs } = require('fs');
const { generateIcons } = require('svg-app-icon');

(async () => {
  const svg = await fs.readFile('my-icon.svg');

  for await (const icon of generateIcons(svg)) {
    await fs.writeFile(path.resolve('./my-output-directory', icon.name), icon.buffer);
  }
})();

generateIcons(svgs, options)AsyncGenerator

The arguments for this method are:

  • svgs String|Buffer|Array<String|Buffer> - the SVG or SVG layers that you'd like to use as the icon. When multiple images are passed in, they will be layered on top of one another in the provided order
  • [options] Object - the options, everything is optional
    • [icns = true] Boolean - whether to generate an ICNS icon for MacOS
    • [ico = true] Boolean - whether to generate an ICO icon for Windows
    • [png = true] Boolean - whether to generate all PNG icon sizes for Linux
    • [svg = true] Boolean - whether to generate output the original SVG to the output destination
    • [pngSizes = [32, 256, 512]] Array<Integer> - the sizes to output for PNG icons, in case you need any additional sizes

The AsyncGenerator will yield icon opject. They contain the following properties:

  • name String: the name of the file.
  • ext String: the extension that should be used for the file. One of ['png', 'icns', 'ico']
  • buffer Buffer: the bytes of the generated icon file
  • size Number: optional, only present for png icons, this is the size that was used to render the icon

💻 CLI

You can also generate icons from the command line, so you don't have to write anything.

npx svg-app-icon < input.svg

Here are all the options (spoiler: they are the same as the API):

Usage:
  svg-app-icon [options] < input.svg

Options:
  --help             Show help
  --version          Show the version
  --destination, -d  Directory to output icons            [string]   [default: icons]
  --layer, -l        Add individual svg images as layers  [string[]]
                     stdin is ignored when using layers
  --include, -i      Which icons to create                [string[]] [default: icns, ico, png, svg]
  --png-size, -s     What size png images create          [number[]] [default: 32, 256, 512]

Note: all array arguments can be defined more than once

Examples:
  svg-app-icon < input.svg
  svg-app-icon --include icns --include ico < input.svg
  svg-app-icon --layer background.svg --layer foreground.svg
  cat input.svg | svg-app-icon --destination build/assets

🤷‍♀️ But Why?

There are very many tools to help you generate desktop app icons. They all, however, take one large PNG file as input and scale it down to generate all the necessary sizes. However, I have two problems:

  • I generate all my icons as SVG and would prefer not to manually pre-process them. I just want to check out the repo and have everything else automated.
  • I noticed that all the PNG-scaling solutions end up creating poor quality PNG images, especially for the smaller sizes. This results in icons that look bad.

Since I use SVG, I actually don't need to scale PNG images. I can arbitrarily generate images of any size from the initial SVG. It just so happens that there are many solutions for that as well. However, for the most part, all have tradeoffs and quality issues as well. This module uses svg-render in order to create high-quality PNGs at any size. You can even use responsive SVGs, to render customized and optimized icons for every size. Try it, it's fun! 🎉