Convert php images to ASCII code

WBOY
Release: 2016-07-25 08:43:22
Original
1807 people have browsed it

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


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!