-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimg2html.php
More file actions
52 lines (45 loc) · 982 Bytes
/
img2html.php
File metadata and controls
52 lines (45 loc) · 982 Bytes
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Created by PhpStorm.
* User: Eason
* Date: 16/2/26
* Time: 下午6:39
*/
// filename
$imgFile = 'img.jpg';
// pixel step
//
// alpha channel
$alpha = 1;
// rotate angle
$angle = 90;
list($width, $height, $type, $attr) = getimagesize($imgFile);
$im = imagecreatefromjpeg($imgFile);
$im = imagerotate($im, $angle, 0);
// rotate fix
$t = $width;
$width = $height;
$height = $t;
$ratio = max($width, $height)*0.15;
$widthStep = $width/$ratio;
$heightStep = $height/$ratio;
ob_start();
echo '
<style type="text/css">
.block{
width:1px;
height:1px;
font-size:1px;
}
</style>';
for ($i = 0; $i < $width; ($i += $widthStep)) {
for ($j = 0; $j < $height; ($j += $heightStep)) {
$rgb = ImageColorAt($im, $i, $j);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
printf('<span class="block" style="color:rgba(%u, %u, %u, %.1f);">▇</span>', $r, $g, $b, $alpha);
}
echo "<br/>";
}
ob_flush();