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
body{
line-height:0;
font-size:1px;
}
$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
5
6
7
8
9
10
11
1213
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...