laradic/icon-generator

生成FontAwesome、Foundation图标或任何自定义图标字体图标,并将其转换为多种尺寸和颜色的图像文件,如.ico/.png

1.0.0 2016-08-14 00:04 UTC

This package is not auto-updated.

Last update: 2024-09-23 14:02:47 UTC


README

Laradic Icon Generator

Source License Framework

Laradic Icon Generator可以从多个图标字体(如FontAwesome、Foundation Icons等)创建PNG图像,例如,用于生成favicon。

此包不需要Laravel,但它提供了ServiceProviderFacade访问和Console命令。

该包遵循FIG标准PSR-1、PSR-2和PSR-4,以确保共享PHP代码之间具有高度的互操作性。

安装

composer require "laradic/icon-generator:~1.0"

快速概述

完整文档 @ la.radic.nl

使用API

工厂是注册自定义字体的地方。Laradic Icon Generator内置了Font AwesomeFoundation Icons

当您想要的字体已被添加到工厂中时,您可以为其创建一个IconGenerator,该生成器负责生成图像。

/** @var \Laradic\IconGenerator\IconGenerator $generator */
$generator = (new \Laradic\IconGenerator\Factory)
                ->addDefaultFonts()
                ->createGenerator('font-awesome');

$generator->setIcons('android', 'car')
            ->setSizes(16, 32, 64, 128)
            ->addColor('#42A5F5') // blue 400
            ->addColor('#424242') // grey 800
            ->addColor(251, 94, 11) // RGB Also supported
            ->setOutDir(__DIR__ . '/generated-icons')
            ->generate();

还有一个shorthand方法可用:\Laradic\IconGenerator\Factory::generate($font, array $icons, array $sizes, array $colors, $outDir = null)

(new Factory())
    ->addDefaultFonts()
    ->generate($font, array $icons, array $sizes, array $colors, $outDir = null);

Laravel

当使用Laravel Service Provider时,工厂被绑定到容器中的singleton。所以上面的例子也可以这样写。

绑定

$generator = app('laradic.icon-generator')
                ->addDefaultFonts()
                ->createGenerator('font-awesome');
// other code remains the same

Facade

可选地,您可以为facade添加代码,并使用它来访问工厂。

$generator = IconGenerator::addDefaultFonts()->createGenerator('font-awesome');

命令

创建字体的另一种方法是使用命令。

Usage:
  laradic:icon:generate [options] [--] <font> [<outDir>]
  laradic:icon:generate font-awesome ./ -i car -i book -s 16 -s 32 -s 128 -c 424242 -c 42A5F5

Arguments:
  font                  The icon font you would like to use
  outDir                Path to the directory the icons should be generated in. [default: "resources/assets/icons"]

Options:
  -i, --icons=ICONS     Icons to generate. One or more icon names (multiple values allowed)
  -s, --sizes=SIZES     The sizes to generate. One or more numeric values (multiple values allowed)
  -c, --colors=COLORS   The colors to generate. Either RGB or HEX (multiple values allowed)
  -l, --list            List all available fonts