Home  >  Article  >  Backend Development  >  Convert php images to ASCII code

Convert php images to ASCII code

WBOY
WBOYOriginal
2016-07-25 08:43:221807browse

PHP images are converted into ASCII codes. After conversion, the images can be displayed directly through strings

  1. Ascii
  2. $image = 'image.jpg';
  3. // Supports http if allow_url_fopen is enabled
  4. $image = file_get_contents($image);
  5. $img = imagecreatefromstring($image);
  6. $width = imagesx($img);
  7. $height = imagesy($img);
  8. for ($h=0;$h<$height;$h++){
  9. for($w=0;$w<=$width;$w++){
  10. $rgb = imagecolorat($img, $w, $h) ;
  11. $a = ($rgb >> 24) & 0xFF;
  12. $r = ($rgb >> 16) & 0xFF;
  13. $g = ($rgb >> 8) & 0xFF;
  14. $b = $rgb & 0xFF;
  15. $a = abs(($a / 127) - 1);
  16. if($w == $width){
  17. echo '
    ';
  18. }else{
  19. echo '#' ;
  20. }
  21. }
  22. }
  23. ?>
Copy code

Convert to, php, ASCII


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn