Laradic Icon Generator
, (*1)
Laradic Icon Generator can create PNG images from several icon fonts like FontAwesome, Foundation Icons, etc.
For example, useful for favicon generation., (*2)
This package does not require Laravel but it does provide a ServiceProvider
, Facade
access and a Console
command., (*3)
The package follows the FIG standards PSR-1, PSR-2, and PSR-4 to ensure a high level of interoperability between shared PHP code., (*4)
Installation
composer require "laradic/icon-generator:~1.0"
Quick Overview
Full documenation @ la.radic.nl, (*5)
Using the API
The factory is the place where you can register custom fonts. Laradic Icon Generator comes packed
with Font Awesome and Foundation Icons., (*6)
When the font you want to use has been added to the factory you can create a IconGenerator
for it which is responsible for generating the images., (*7)
/** @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();
There's also a shorthand method available \Laradic\IconGenerator\Factory::generate($font, array $icons, array $sizes, array $colors, $outDir = null)
, (*8)
(new Factory())
->addDefaultFonts()
->generate($font, array $icons, array $sizes, array $colors, $outDir = null);
Laravel
When using the Laravel Service Provider, the factory is bound as singleton in the container.
So the example above can also be written like this., (*9)
Binding
$generator = app('laradic.icon-generator')
->addDefaultFonts()
->createGenerator('font-awesome');
// other code remains the same
Facade
Optionally, you could add the facade and use that for accessing the factory., (*10)
$generator = IconGenerator::addDefaultFonts()->createGenerator('font-awesome');
Command
Another way to create fonts is using the command., (*11)
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