Php to convert images into ASCII codes
The details are as follows:
Convert a php image to an ASCII code. After conversion, you can directly display the image using a string.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<Html> <Head> <Title> Ascii </title> <Style> Body { Line-height: 0; Font-size: 1px; } </Style> </Head> <Body> <? Php $ Image = 'image.jpg '; // Supports http if allow_url_fopen is enabled $ Image = file_get_contents ($ image ); $ Img = imagecreatefromstring ($ image ); $ Width = imagesx ($ img ); $ Height = imagesy ($ img ); For ($ h = 0; $ h <$ height; $ h ++ ){ For ($ w = 0; $ w <= $ width; $ w ++ ){ $ Rgb = imagecolorat ($ img, $ w, $ h ); $ A = ($ rgb> 24) & 0xFF; $ R = ($ rgb> 16) & 0xFF; $ G = ($ rgb> 8) & 0xFF; $ B = $ rgb & 0xFF; $ A = abs ($ a/127)-1 ); If ($ w = $ width ){ Echo '<br> '; } Else { Echo '<span style = "color: rgba ('. $ r. ','. $ g. ','. $ B. ','. $. '); ">#</span> '; } } } ?> </Body> </Html> |