-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
241 lines (198 loc) · 8.45 KB
/
index.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
include_once './includes/autoload.php';
use Com\Jpexs\Image\IconReader;
use Com\Jpexs\Image\IconWriter;
use Com\Jpexs\Image\ExeIconReader;
use Com\Jpexs\Image\AniReader;
use Com\Jpexs\Image\AniWriter;
$testIcoFile = "./samples/test.ico";
$testCurFile = "./samples/test.cur";
$testExeFile = "./samples/test.exe";
$testAniFile = "./samples/test.ani";
$action = "html";
if (array_key_exists("action", $_GET)) {
$action = $_GET["action"];
}
if ($action === "html") {
echo '<!DOCTYPE html>
<html>
<head>
<title>JPEXS Icon library samples</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body bgcolor="#8f8">';
$bitNames = [
1 => "1bit - black and white",
4 => "4bit - 16 colors",
8 => "8bit - 256 colors",
24 => "24bit - True colors",
32 => "32bit - True colors + alpha channel"
];
echo '<h1>JPEXS Icon library samples</h1>';
echo '<h2>1) Icon generation</h2>';
echo '<a href="index.php?action=generate_icon">Download icon</a>';
echo '<h2>2) List of icons of ' . $testIcoFile . ':</h2>';
$iconReader = IconReader::createFromIcoFile($testIcoFile);
foreach ($iconReader as $imageId => $iconImage) {
echo $iconImage->getWidth() . " x " . $iconImage->getHeight();
echo ", " . $bitNames[$iconImage->getColorsBitCount()] . "<br>";
echo '<img src="index.php?action=icon_to_png&imageId=' . $imageId . '" /> <br />';
}
echo '<h2>3) List of icons of ' . $testExeFile . '</h2>';
$exeReader = ExeIconReader::createFromExeFile($testExeFile);
echo $exeReader->getIconCount() . " icon groups<br>";
foreach ($exeReader as $iconId => $icon) {
echo "<h3>icon group $iconId</h3>";
echo '<a href="index.php?action=exe_icon_export&iconId=' . $iconId . '">export ICO file</a><br>';
foreach ($icon as $imageId => $iconImage) {
echo $iconImage->getWidth() . " x " . $iconImage->getHeight();
echo ", " . $bitNames[$iconImage->getColorsBitCount()] . "<br>";
echo '<img src="index.php?action=exe_icon_to_png&iconId=' . $iconId . "&imageId=" . $imageId . '" /> <br />';
}
}
echo '<h2>4) Cursor display</h2>';
$iconReader = IconReader::createFromCurFile($testCurFile);
$cursorImage = $iconReader->getCursorImage();
echo $cursorImage->getWidth() . " x " . $cursorImage->getHeight();
echo ", " . $bitNames[$cursorImage->getColorsBitCount()] . "<br>";
echo "hotspot x: " . $cursorImage->getHotSpotX().", hotspot y:" . $cursorImage->getHotSpotY() . "<br>";
echo '<img src="index.php?action=cursor_to_png" /> <br />';
echo '<h2>5) Generate cursor</h2>';
echo '<div style="width:200px; height:200px; background-color: #f00; cursor: url(\'index.php?action=generate_cursor\'), auto;">sample div - hover to show cursor</div>';
echo '<h2>6) Details of animation in ' . $testAniFile . ':</h2>';
$aniReader = AniReader::createFromAniFile($testAniFile);
echo $aniReader->getWidth() . " x " . $aniReader->getHeight();
echo ", " . $bitNames[$aniReader->getColorsBitCount()] . "<br>";
echo "name: " . $aniReader->getName() . "<br>";
echo "artist: " . $aniReader->getArtist() . "<br>";
foreach ($aniReader as $imageId => $iconImage) {
echo '<img src="index.php?action=ani_to_png&imageId=' . $imageId . '" /> <br />';
}
echo '<h2>7) Generate ANI cursor</h2>';
echo '<div style="width:200px; height:200px; background-color: #f00; cursor: url(\'index.php?action=generate_ani\'), auto;">'
. 'sample div - hover to show ANI cursor, however, as of 2022, no major browser supports ANI files :-('
. '</div><br>';
echo '<a href="index.php?action=generate_ani">download ANI animation</a>';
echo '</body>
</html>';
exit;
}
if ($action === "icon_to_png") {
header("Content-type: image/png");
$iconReader = IconReader::createFromIcoFile($testIcoFile);
$iconImage = $iconReader->getIconImage($_GET["imageId"]);
$image = $iconImage->getImage();
imagepng($image);
exit;
}
if ($action === "generate_icon") {
header("Content-type: image/x-icon");
header('Content-Disposition: attachment; filename="generated.ico"');
$sizes = [256, 128, 64, 48, 32, 16];
$images = [];
foreach ($sizes as $size) {
//alpha image
$image = imagecreatetruecolor($size, $size);
imagealphablending($image, false);
imagesavealpha($image, true);
$transparent = imagecolorallocatealpha($image, 0, 0, 0, 127);
$red = imagecolorallocatealpha($image, 255, 0, 0, 64);
imagefill($image, 0, 0, $transparent);
imagefilledellipse($image, $size / 2, $size / 2, $size, $size, $red);
$images[] = $image;
//standard image with trasparent background
$image = imagecreatetruecolor($size, $size);
$transparent = imagecolorallocate($image, 255, 255, 255);
$red = imagecolorallocate($image, 255, 0, 0);
imagefill($image, 0, 0, $transparent);
imagefilledellipse($image, $size / 2, $size / 2, $size, $size, $red);
imagecolortransparent($image, $transparent);
$images[] = $image;
}
$writer = new IconWriter();
$writer->createToPrint($images);
exit;
}
if ($action === "exe_icon_to_png") {
header("Content-type: image/png");
$exeReader = ExeIconReader::createFromExeFile($testExeFile);
$iconImage = $exeReader->getIcon($_GET["iconId"])->getIconImage($_GET["imageId"]);
$image = $iconImage->getImage();
imagepng($image);
exit;
}
if ($action === "exe_icon_export") {
$iconId = $_GET["iconId"];
header("Content-type: image/x-icon");
header('Content-Disposition: attachment; filename="' . $iconId . '.ico"');
$exeReader = ExeIconReader::createFromExeFile($testExeFile);
echo $exeReader->getIconData($iconId);
exit;
}
if ($action === "cursor_to_png") {
header("Content-type: image/png");
$iconReader = IconReader::createFromCurFile($testCurFile);
$cursorImage = $iconReader->getCursorImage();
$image = $cursorImage->getImage();
imagepng($image);
exit;
}
if ($action === "generate_cursor") {
header("Content-type: image/vnd.microsoft.icon");
$writer = new IconWriter();
$image = imagecreate(32, 32);
$background = imagecolorallocate($image, 255, 0, 255);
imagefill($image, 0, 0, $background);
$blue = imagecolorallocate($image, 0, 0, 255);
$yellow = imagecolorallocate($image, 255, 255, 0);
$polygon = [
5, 5,
20, 5,
5, 20,
];
imagefilledpolygon($image, $polygon, count($polygon)/2, $blue);
imagepolygon($image, $polygon, count($polygon)/2, $yellow);
imagecolortransparent($image, $background);
$writer->createCursorToPrint($image, 5, 5);
exit;
}
if ($action === "ani_to_png") {
header("Content-type: image/png");
$aniReader = AniReader::createFromAniFile($testAniFile);
$iconImage = $aniReader->getIconImage($_GET["imageId"]);
$image = $iconImage->getImage();
imagepng($image);
}
if ($action === "generate_ani") {
header("Content-type: application/x-navi-animation");
header('Content-Disposition: attachment; filename="generated.ani"');
$aniWriter = new AniWriter();
$aniWriter->setArtist("Jindra Petrik");
$aniWriter->setName("My Generated animated cursor");
$aniWriter->setDefaultFrameRate(5);
$steps = 10;
$startR = 0; $startG = 0; $startB = 255;
$endR = 0; $endG = 255; $endB = 0;
for ($i = 0; $i < $steps; $i++) {
$image = imagecreate(32, 32);
$background = imagecolorallocate($image, 255, 0, 255);
imagefill($image, 0, 0, $background);
$fillColor = imagecolorallocate($image,
round($startR + ($endR - $startR) * $i / $steps),
round($startG + ($endG - $startG) * $i / $steps),
round($startB + ($endB - $startB) * $i / $steps),
);
$black = imagecolorallocate($image, 0, 0, 0);
$polygon = [
5, 5,
20, 5,
5, 20,
];
imagefilledpolygon($image, $polygon, count($polygon)/2, $fillColor);
imagepolygon($image, $polygon, count($polygon)/2, $black);
imagecolortransparent($image, $background);
$aniWriter->addImage($image, 5, 5);
}
$aniWriter->createToPrint();
}