-
Notifications
You must be signed in to change notification settings - Fork 1
/
js2png.php
111 lines (98 loc) · 2 KB
/
js2png.php
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
function p($obj)
{
echo '<pre>';
print_r($obj);
echo '<pre>';
}
function allInOne($js_files)
{
$content = '';
ksort($js_files);
foreach ($js_files as $js_file)
{
if (!file_get_contents($js_file))
die("whate da fuck ".$js_file);
$content .= file_get_contents($js_file);
}
unset($js_files, $js_file);
file_put_contents('oneJSForRuleThemAll.js', $content);
}
function combineJS($path)
{
$js_files = array();
$is_dot = array ('.', '..');
if (is_dir($path))
{
if (version_compare(phpversion(), '5.3', '<'))
{
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::SELF_FIRST
);
}
else
{
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
);
}
foreach ($iterator as $pathname => $file)
{
if (version_compare(phpversion(), '5.2.17', '<='))
{
if (in_array($file->getBasename(), $is_dot))
continue;
}
elseif (version_compare(phpversion(), '5.3', '<'))
{
if ($file->isDot())
continue;
}
if ($file->getExtension() === 'js')
$js_files[] = $file->getPathname();
}
allInOne($js_files);
unset($iterator, $file);
}
}
function convertJS($filename)
{
if (file_exists($filename))
{
$iFileSize = filesize($filename);
$iWidth = ceil(sqrt($iFileSize / 1));
$iHeight = $iWidth;
$im = imagecreatetruecolor($iWidth, $iHeight);
$fs = fopen($filename, 'r');
$data = fread($fs, $iFileSize);
fclose($fs);
$i = 0;
for ($y=0; $y < $iHeight; $y++)
{
for ($x=0; $x < $iWidth; $x++)
{
$ord = ord(@$data[$i]);
imagesetpixel($im,
$x, $y,
imagecolorallocate($im,
$ord,
$ord,
$ord
)
);
$i++;
}
}
imagepng($im, 'oneJSForRuleThemAll.png');
imagedestroy($im);
p('Image created oneJSForRuleThemAll.png');
}
}
function JSToPng($dir)
{
combineJS($dir);
convertJS('oneJSForRuleThemAll.js');
}
JSToPng('./js/');