Convert photo to ASCII


SUBMITTED BY: Guest

DATE: March 26, 2015, 1:50 p.m.

FORMAT: PHP

SIZE: 1.0 kB

HITS: 5409

  1. ?>
  2. <body>
  3. <style>
  4. body{
  5. line-height:1px;
  6. font-size:1px;
  7. }
  8. </style>
  9. </head>
  10. <body>
  11. <?php
  12. function getextention($filename) {
  13. $pos = strrpos($filename,'.');
  14. $str = substr($filename, $pos);
  15. return $str;
  16. }
  17. $image = 'votreimage.jpg';
  18. $ext = getextention($image);
  19. if($ext == ".jpg"){
  20. $img = ImageCreateFromJpeg($image);
  21. }
  22. else{
  23. echo'mauvais fichier image';
  24. }
  25. $width = imagesx($img);
  26. $height = imagesy($img);
  27. for($h=0;$h<$height;$h++){
  28. for($w=0;$w<=$width;$w++){
  29. $rgb = ImageColorAt($img, $w, $h);
  30. $r = ($rgb >> 16) & 0xFF;
  31. $g = ($rgb >> 8) & 0xFF;
  32. $b = $rgb & 0xFF;
  33. if($w == $width){
  34. echo '<br />';
  35. }else{
  36. echo '<span style="color:rgb('.$r.','.$g.','.$b.');">#</span>';
  37. }
  38. }
  39. }
  40. ?>
  41. </body>

comments powered by Disqus