How to convert images into ASCII code in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 09:58:17
Original
738 people have browsed it

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...
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