Home  >  Article  >  Backend Development  >  How to convert images into ASCII code in PHP_PHP Tutorial

How to convert images into ASCII code in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 09:58:17736browse

How to convert images into ASCII codes in PHP

The details are as follows:

Convert PHP images into ASCII codes, and after conversion, the images can be displayed directly through strings

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

Ascii

$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 '
';

}else{

echo '#';

}

}

}

?>

1 2 3

4

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
Ascii <๐ŸŽœ>$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 '
'; }else{ echo '#< /span>'; } } } ?>
http://www.bkjia.com/PHPjc/978263.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/978263.htmlTechArticleThe method of converting pictures into ASCII codes in php is as follows: Convert php pictures into ASCII codes. After conversion, you can directly pass String display picture 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18...
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