SAMIHOLCK.FI

Icons and icon factories

All icon libraries support assistive reading technologies.

Font Awesome

Font Awesome icons can be used by creating a Icon or a FontAwesomeIcon object.

FontAwesomeIcon Icon size can be changed simply by calling FontAwesomeIcon::setSize() method with a Font Awesome CSS class (or a short hand version of it by simply removing the fa- from the begining of the size class)

Sizes are:

  • fa-xs - .75em
  • fa-sm - .875em
  • fa-lg - 1.33em, also applies vertical-align: -25%
  • fa-2x through fa-10x - 2em through 10em

<?php

use Sphp\Media\Icons\IconObject;
use Sphp\Media\Icons\FontAwesome;

$factory = new FontAwesome();
$factory->useTitle('Factory example title');
$factory->fixedWidth(true);
echo new IconObject('fab fa-creative-commons');
echo $factory->createIcon('fab fa-creative-commons');
echo $factory->createIcon('fab fa-creative-commons')->setSize('2x');
echo $factory->createIcon('fab fa-html5')->setSize('3x');
echo $factory->createIcon('fab fa-python')->setSize('4x');
echo $factory->createIcon('fab fa-facebook-square')->setSize('5x');
echo $factory->createIcon('fab fa-blogger')->setSize('6x');
echo $factory->createIcon('fab fa-css3')->setSize('7x');
echo $factory->createIcon('fab fa-npm')->setSize('8x');
echo $factory->createIcon('fab fa-gulp')->setSize('9x');
echo $factory->createIcon('fab fa-sass')->setSize('10x');

Devicons

Devicons icon factory uses Devicon v2 library. Devicons is a set of icons representing programming languages, designing and development tools. These icons are available as fonts and SVG images and they support assistive reading technologies.

<?php

use Sphp\Media\Icons\Devicon;
use Sphp\Media\Icons\Devicons;

$factory = new Devicons();
$factory->useTitle('Factory example title');
$list = new \Sphp\Html\Lists\Ul;
$list->append(new Devicon('devicon-devicon-plain-wordmark'))->css()->setProperty('font-size', '2rem');
$list->append($factory
                ->createIcon('devicon-devicon-plain-wordmark')
                ->setColored(true))
        ->css()->setProperty('font-size', '2rem');
echo $list;

Other icon factories

Filetype icons and SVG country flags

Filetype icon factory

Filetype icons

<?php

use Sphp\Media\Icons\FileTypeIcons; 

$files = [
    '../',
    'foo.bar',
    new SplFileObject('./index.php'),
    'python.py',
    'ai.ai',
    'ini',
];
$icons = FileTypeIcons::defaultSet();
foreach ($files as $file) {
  echo $icons->createIconFor($file) . " $file
"; } $icons->setExtensionIcon('bar', 'far fa-smile'); echo $icons->createIconFor('foo.bar') . " special icon for *.bar files
";

../
foo.bar
python.py
ai.ai
ini
special icon for *.bar files

External Icon resources

  1. Font Awesome: https://fontawesome.com/
  2. Devicon 2.0: https://konpa.github.io/devicon/
  3. Jam Icons: https://jam-icons.com/
  4. Material Design Icons: https://materialdesignicons.com/