summaryrefslogtreecommitdiff
path: root/jtanimator.php
diff options
context:
space:
mode:
authorstage7 <stage7@stg7.net>2024-09-28 23:45:49 +0200
committerstage7 <stage7@stg7.net>2024-09-28 23:45:49 +0200
commite88dcc3ceb38cb0d4494016df7556e968f97a678 (patch)
treea7b47817c9e63233b02fe9170b3278cee94331a5 /jtanimator.php
downloadjtanimator-1.0.tar.gz
jtanimator-1.0.tar.bz2
jtanimator-1.0.zip
First commitHEADv1.0master
Diffstat (limited to 'jtanimator.php')
-rw-r--r--jtanimator.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/jtanimator.php b/jtanimator.php
new file mode 100644
index 0000000..ff04f01
--- /dev/null
+++ b/jtanimator.php
@@ -0,0 +1,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>";