Giter Site home page Giter Site logo

pixeler's Introduction

Pixeler

Gitter

Render images in CLI with UTF-8 characters.

Scrutinizer Code Quality Total Downloads Latest Stable Version Latest Unstable Version License

Installation

Require in your project with composer :

$ composer require lastguest/pixeler

This will also install a pixeler tool in :

your_project_dir/vendor/bin/pixeler

It works exactly like the example below.

Example

Create a file pixel.php :

<?php

// Include autoloader
include __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;
$ php pixel.php -f http://drop.caffeina.co/image/160L0Y3C0a29/vocaloid.jpg -r .25 -w 0.25 -i

$ php pixel.php -f http://flippywall.com/wp-content/uploads/2014/07/Manga-Girl-Wallpaper-16.jpg -r 0.15 -w 0.5 -i

$ php pixel.php -f http://blog.circleci.com/wp-content/uploads/2014/07/elephant.jpg -r 0.3 -w 0.5 -b

Dithering

Use the -d option to choose 1-bit dithering mode.

Command Constant Description
-d0 Pixeler\Image::DITHER_NONE Threshold 1-bit quantization
-d1 Pixeler\Image::DITHER_ERROR Dither image with 1-bit Atkinson Dithering

Animation Example

You will see a lot of tearing, need some kind of vsync wait.

<?php

// Vendors
include __DIR__."/vendor/autoload.php";

$screen = new Pixeler\Canvas(160,100);
$sh2 = $screen->height()/2;
$sh4 = $sh2/1.5;
$ph = pi()/32;
$i = 0;

// To exit, press Ctr-C
while(1){
  $screen->clear();
  for ($x=0,$c=$screen->width(); $x < $c; $x++){
    $y = $sh4*sin($i++/128 + $ph*$x);
    $screen->setPixel($x,$sh2 + $y);
    $screen->setPixel($x,$sh2 + $y/2);
    $screen->setPixel($x,$sh2 + $y/4);
    $screen->setPixel($x,$sh2);
  }
  echo $screen;
}

pixeler's People

Contributors

anahkiasen avatar bitdeli-chef avatar danielruf avatar gitter-badger avatar jawira avatar jcbwlkr avatar lastguest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pixeler's Issues

Fails on image URL with query string

Fails on image URL with query string and reports: Image format not supported.

Workaround might look like:

$urlArray = parse_url($result->thumb);
Pixeler\Pixeler::image($urlArray['scheme'] . '://' . $urlArray['host'] . $urlArray['path']);

or

$url= strtok($result->thumb, '?');
Pixeler\Pixeler::image($url);

Print UTF-8 character and color

Hello,

I found another issue under Ubuntu (Linux) that is causing the output of color codes like [0[38;5;144m in the output. This is caused by echo $ESC."[0\n"; in line 113 in Matrix.php.

Switching to echo "n"; solved the issue for me.

Original version:
pixel_unfixed

Fixed version:
pixel-fixed

Restore colors after printing

Hello,

I like this library but there seems to be an issue while echoing text right after the image. The colors are not being restore to the default so the text is also colored.

Update composer.json

The composer.json is missing the update to the latest version. Therefore the latest release cannot be used as dependency.

Feature request: Video Support

Hello,

what about video support using PHP-FFMpeg?

$video
    ->filters()
    ->extractMultipleFrames(FFMpeg\Filters\Video\ExtractMultipleFramesFilter::FRAMERATE_EVERY_10SEC, '/path/to/destination/folder/')
    ->synchronize();

and then loop over the result using the Pixeler\Canvas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.