承接 alto/favicon 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alto/favicon

Composer 安装命令:

composer require alto/favicon

包简介

Generate a modern favicon set (SVG icon, apple-touch-icon, favicon.ico, Web Manifest) from a single SVG or PNG file.

README 文档

README

A modern, efficient PHP library and CLI tool to generate a complete favicon set from a single SVG or PNG source.

It follows the modern best practices (2025) to generate a minimal yet robust set of icons for all browsers and devices.

Features

  • Minimal Output: Generates only the necessary files to cover all modern use cases.
  • SVG Support: Preserves your vector logo for modern browsers (icon.svg).
  • Legacy Support: Generates a 32x32 favicon.ico for older browsers.
  • Mobile Ready: Generates apple-touch-icon.png and Android icons (icon-192.png, icon-512.png).
  • PWA Ready: Automatically generates a manifest.webmanifest.
  • Search Friendly: Optionally generates a 48x48 PNG for Google Search results.
  • HTML Snippet: Outputs the exact HTML tags you need to include in your <head>.
  • Flexible Rasterization: Supports multiple adapters for image processing:
    • SVG: rsvg-convert, inkscape, or imagemagick (CLI)
    • PNG: ext-imagick or ext-gd

Requirements

  • PHP 8.3 or higher
  • For PNG processing: ext-imagick (recommended) OR ext-gd
  • For SVG input, one of the following must be installed on your system:
    • rsvg-convert (part of librsvg, recommended)
    • inkscape
    • imagemagick (magick or convert)

Installation

composer require alto/favicon

Usage

CLI

Run the tool using the binary:

vendor/bin/favicon path/to/logo.svg

Programmatic Usage

You can use the FaviconGenerator class directly in your PHP application (e.g., in a CMS, build script, or controller).

use Alto\Favicon\Generator\FaviconGenerator;
use Alto\Favicon\Options\FaviconOptionsBuilder;

// 1. Configure options
$options = (new FaviconOptionsBuilder(
    inputFile: 'assets/logo.svg',
    outputDir: 'public/favicons'
))
    ->publicPath('/favicons')
    ->appName('My App')
    ->themeColor('#0b0b0b')
    ->build();

// 2. Generate
$generator = new FaviconGenerator();
$report = $generator->generate($options);

// 3. Use the result
echo "Generated " . count($report->files) . " files.\n";
echo "HTML Snippet:\n" . $report->htmlSnippet;

FaviconOptionsBuilder API

Method Description Default
__construct(string $inputFile, string $outputDir) Initialize with input file and output directory. -
publicPath(string $path) Set the public URL prefix for generated files. /
appName(string $name) Set the application name for the manifest. App
themeColor(string $color) Set the theme color (meta tag & manifest). #0b0b0b
backgroundColor(string $color) Set the background color (manifest). #ffffff
generateManifest(bool $generate) Enable/disable manifest generation. false
generateSearchPng48(bool $generate) Enable/disable 48x48 PNG generation. false
force(bool $force) Enable/disable overwriting existing files. false
build(): FaviconOptions Build the options object. -

GenerationReport Properties

The generate() method returns a GenerationReport object with the following properties:

  • outputDir (string): The directory where files were written.
  • publicPath (string): The public URL prefix used.
  • files (array<string, int>): Map of generated filenames to their size in bytes.
  • htmlSnippet (string): The HTML tags to include in your <head>.
  • manifestFile (?string): The name of the manifest file (if generated).
  • totalBytes() (int): Helper method to get total size of generated files.

Options (CLI)

Option Description Default
--output, -o Output directory for generated files public
--public-path Public path prefix used in HTML/manifest /
--app-name Application name used in the manifest App
--theme-color Theme color for browser UI and manifest #0b0b0b
--background-color Background color for the manifest #ffffff
--manifest Generate manifest.webmanifest and Android icons false
--search-png Generate the 48x48 PNG favicon false
--force, -f Overwrite existing files false

Examples

Basic usage (Minimal set):

vendor/bin/favicon assets/logo.svg

Full set with Manifest and Search Icon:

vendor/bin/favicon assets/logo.svg --manifest --search-png

Customizing output and colors:

vendor/bin/favicon assets/logo.svg \
    --output public/assets/favicons \
    --public-path /assets/favicons \
    --app-name "My Awesome App" \
    --theme-color "#3b82f6"

Using a PNG source (if you don't have SVG):

vendor/bin/favicon assets/logo.png

Note: When using PNG input, icon.svg will not be generated, and 16x16/32x32 PNGs will be used as fallbacks.

Generated Files

The tool generates the following structure in your output directory:

  • favicon.ico (Legacy support)
  • icon.svg (Modern browsers)
  • apple-touch-icon.png (iOS)
  • favicon.html (HTML snippet to include)

Optional files (with --manifest and --search-png):

  • icon-192.png (Android)
  • icon-512.png (Android)
  • icon-maskable.png (Android maskable icon)
  • manifest.webmanifest (Web App Manifest)
  • favicon-48x48.png (Google Search)

Testing

To run the test suite:

composer test

License

This project is licensed under the MIT License.

alto/favicon 适用场景与选型建议

alto/favicon 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22 次下载、GitHub Stars 达 4, 最近一次更新时间为 2025 年 12 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「generator」 「php」 「cli」 「png」 「manifest」 「svg」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 alto/favicon 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 alto/favicon 我们能提供哪些服务?
定制开发 / 二次开发

基于 alto/favicon 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 22
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 31
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-24