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
|
<?php
$filename = "hex.png";
$im = imagecreatefrompng($filename);
list($width, $height, $type, $attr) = getimagesize($filename);
$bitsData = ["", "", ""];
$pixelNumber = 0;
for ($image = 0; $image < $height / 16; $image++) {
for ($x = 0; $x < 32; $x++) {
for ($y = 0; $y < 16; $y++) {
$col = imagecolorat($im, $x, $y + $image * 16);
if (($col >> 16) & (0xff == 255)) { $bitsData[0] .= "1"; } else { $bitsData[0] .= "0"; }
if (($col >> 8) & (0xff == 255)) { $bitsData[1] .= "1"; } else { $bitsData[1] .= "0"; }
if ($col & (0xff == 255)) { $bitsData[2] .= "1"; } else { $bitsData[2] .= "0"; }
if ($pixelNumber > 0 && $pixelNumber % 8 == 7) {
$bitsData[0] .= ",";
$bitsData[1] .= ",";
$bitsData[2] .= ",";
}
$pixelNumber++;
}
}
}
$aniData = [];
$toDec = function ($value) {
return bindec($value);
};
for ($i = 0; $i < 3; $i++) {
$tempData = explode(",", $bitsData[$i]);
array_pop($tempData);
$tempDataDec = array_map($toDec, $tempData);
for ($j = 0; $j < count($tempDataDec); $j++) {
$aniData[] = $tempDataDec[$j];
}
}
echo "<pre>";
print_r('[{"data":{"aniData":[');
print_r(implode(",", $aniData));
print_r('],"aniType":1,"delays":300,"frameNum":' . $height / 16 . ',"pixelHeight":16,"pixelWidth":32},"dataType":0}]');
echo "</pre>";
|