diff options
Diffstat (limited to 'jtanimator.php')
-rw-r--r-- | jtanimator.php | 46 |
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>"; |