image2asciiart.php 672 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. require_once 'bootstrap.php';
  3. $charMap = '@#W$9876543210?!abc;:+=-,._ ';
  4. $len = strlen($charMap);
  5. $result = '';
  6. $pixelCraft->loadImage('../assets/horse.png');
  7. $filterSet = array();
  8. $filterSet []= array(IMG_FILTER_NEGATE =>'');
  9. $pixelCraft->imageFilters($filterSet);
  10. $pixelCraft->pixelate(3, true);
  11. $pixelCraft->resize(64, 64);
  12. $colorMap = $pixelCraft->getColorMap(false);
  13. foreach ($colorMap as $x => $ys) {
  14. foreach ($ys as $y => $color) {
  15. $brightness = $pixelCraft->rgbToBrightness($color);
  16. $charIndex = floor(($brightness * $len) / 255);
  17. $result .= $charMap[$charIndex].' ';
  18. }
  19. $result .= PHP_EOL;
  20. }
  21. print($result);