Generate PNG icons from SVG for iOS and PWA compatibility
npm install @profullstack/favicon-generatorGenerate PNG icons from SVG for iOS and PWA compatibility. A modern, flexible Node.js tool that converts your SVG favicon into all the icon sizes you need for mobile devices and progressive web apps.


- 🎨 Convert SVG to multiple PNG icon sizes
- 📱 iOS Apple Touch Icon support
- 🌐 PWA icon generation
- 🖼️ Automatic favicon size generation (16x16, 32x32)
- ⚙️ Configurable quality and compression
- 🎯 CLI with interactive mode
- 📦 ESM module for programmatic use
- ✅ Comprehensive test coverage
- 🚀 Built with modern Node.js (v20+)
``bashUsing pnpm (recommended)
pnpm add @profullstack/favicon-generator
$3
`bash
Using pnpm
pnpm add -g @profullstack/favicon-generatorUsing npm
npm install -g @profullstack/favicon-generator
`Usage
$3
#### Interactive Mode
Simply run the command without arguments to enter interactive mode:
`bash
fav
`You'll be prompted for:
- SVG file path
- Output directory
- PNG quality (1-100)
- Compression level (0-9)
- Whether to generate additional favicon sizes
#### Command Line Arguments
`bash
Basic usage
fav -i favicon.svg -o ./iconsWith custom quality and compression
fav -i logo.svg -o ./public/icons -q 90 -c 7Silent mode (no output)
fav -i favicon.svg -o ./icons --silentSkip favicon generation
fav -i favicon.svg -o ./icons --no-faviconShow help
fav --helpShow version
fav --version
`#### CLI Options
| Option | Alias | Description | Default |
| --------------- | ----- | ----------------------------- | --------------- |
|
--input | -i | Path to SVG file | ./favicon.svg |
| --output | -o | Output directory | ./icons |
| --quality | -q | PNG quality (1-100) | 95 |
| --compression | -c | Compression level (0-9) | 9 |
| --no-favicon | | Skip additional favicon sizes | false |
| --silent | | Suppress output messages | false |
| --help | -h | Show help message | |
| --version | -v | Show version number | |$3
#### Basic Example
`javascript
import { generateIcons } from '@profullstack/favicon-generator';const results = await generateIcons({
svgPath: './favicon.svg',
outputDir: './icons',
});
console.log(
Generated ${results.icons.length} icons);
`#### Custom Configuration
`javascript
import { generateIcons } from '@profullstack/favicon-generator';const results = await generateIcons({
svgPath: './logo.svg',
outputDir: './public/icons',
quality: 90,
compressionLevel: 7,
generateFavicon: true,
faviconSizes: [16, 32, 48],
verbose: true,
});
// Access generated files
results.icons.forEach((icon) => {
console.log(
${icon.name}: ${icon.path});
});
`#### Custom Icon Sizes
`javascript
import { generateCustomIcons } from '@profullstack/favicon-generator';const customSizes = [
{ size: 48, name: 'icon-48.png' },
{ size: 96, name: 'icon-96.png' },
{ size: 144, name: 'icon-144.png' },
];
const results = await generateCustomIcons('./favicon.svg', './icons', customSizes, { quality: 95 });
`#### Using Constants
`javascript
import { generateIcons, DEFAULT_ICON_SIZES, BACKGROUNDS } from '@profullstack/favicon-generator';// Use default icon sizes
const results = await generateIcons({
svgPath: './favicon.svg',
outputDir: './icons',
iconSizes: DEFAULT_ICON_SIZES,
});
// Available background colors
console.log(BACKGROUNDS.transparent); // { r: 255, g: 255, b: 255, alpha: 0 }
console.log(BACKGROUNDS.white); // { r: 255, g: 255, b: 255, alpha: 1 }
console.log(BACKGROUNDS.black); // { r: 0, g: 0, b: 0, alpha: 1 }
`API Reference
$3
Generate PNG icons from an SVG file.
Parameters:
-
options (Object):
- svgPath (string, required): Path to the SVG file
- outputDir (string, required): Output directory for generated icons
- iconSizes (Array, optional): Array of {size, name} objects. Defaults to DEFAULT_ICON_SIZES
- quality (number, optional): PNG quality (1-100). Default: 95
- compressionLevel (number, optional): Compression level (0-9). Default: 9
- generateFavicon (boolean, optional): Generate additional favicon sizes. Default: true
- faviconSizes (Array, optional): Array of favicon sizes. Default: [16, 32]
- verbose (boolean, optional): Enable verbose logging. Default: trueReturns: Promise
`javascript
{
icons: [
{ size: 64, name: 'icon-64.png', path: './icons/icon-64.png' },
// ...
],
faviconSizes: [
{ size: 16, path: './icons/favicon-16.png' },
// ...
],
outputDir: './icons'
}
`$3
Generate icons with custom sizes.
Parameters:
-
svgPath (string): Path to the SVG file
- outputDir (string): Output directory
- customSizes (Array): Array of {size, name} objects
- additionalOptions (Object, optional): Additional options (quality, compressionLevel, etc.)Returns: Promise
generateIcons)Default Icon Sizes
The package generates the following icon sizes by default:
$3
- 57x57, 60x60, 72x72, 76x76
- 114x114, 120x120, 144x144
- 152x152, 180x180
$3
- 192x192, 256x256, 384x384, 512x512
$3
- 16x16, 32x32
Using Generated Icons in HTML
After generating your icons, add them to your HTML
section. See the complete example in examples/html-head-template.html.$3
`html
`$3
Create a
manifest.json file for Progressive Web App support. See examples/manifest.json for a complete example:`json
{
"name": "Your App Name",
"short_name": "App",
"icons": [
{
"src": "/icons/icon-192x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "/icons/icon-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any maskable"
}
],
"start_url": "/",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#ffffff"
}
`$3
- iOS: Uses Apple Touch Icons (automatically adds rounded corners)
- Android/PWA: Uses icons from manifest.json
- Windows: Uses msapplication meta tags
- Modern Browsers: Prefer SVG favicon with PNG fallbacks
Development
$3
`bash
Clone the repository
git clone https://github.com/profullstack/favicon-generator.git
cd favicon-generatorInstall dependencies
pnpm install
`$3
`bash
Run tests
pnpm testRun tests in watch mode
pnpm test:watchRun tests with coverage
pnpm test:coverage
`$3
`bash
Lint code
pnpm lintFix linting issues
pnpm lint:fixFormat code
pnpm formatCheck formatting
pnpm format:check
``- Node.js >= 20.0.0
- ESM support
- sharp - High-performance image processing
- inquirer - Interactive CLI prompts
MIT © profullstack
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any issues or have questions, please file an issue on the GitHub repository.
See CHANGELOG.md for release history.