PHP Classes

File: bin/pixeler

Recommend this page to a friend!
  Classes of Stefano Azzolini   Pixeler   bin/pixeler   Download  
File: bin/pixeler
Role: Example script
Content type: text/plain
Description: Example CLI tool
Class: Pixeler
Render images as UTF-8 text characters
Author: By
Last change: Fixed broken bin file
Date: 8 years ago
Size: 731 bytes


Class file image Download
#!/usr/bin/env php

// Include autoloader
require __DIR__.'/../vendor/autoload.php';

// Parse options from command line
$opts = array_merge([
'd' => 1, // Dithering mode : 0 = DITHER_NONE, 1 = DITHER_ERROR
'f' => false,
'r' => 1.0, // Resize factor 1.0 = 100%
'w' => 0.75, // Dither treshold weight
], getopt("f:r:w:d:ib"));

// An image file/url is required.
$opts['f'] || die("Must specify an image file.\n");

// The -i option inverts the image
$image = Pixeler\Pixeler::image($opts['f'], $opts['r'], isset($opts['i']), $opts['w'], $opts['d']);

// No colors if "-b" is passed
isset($opts['b']) && $image->clearColors();

// The Pixeler\Image instance render itself if casted to a string
echo $image;