function read4ByteDate() { $y = readShort(); $m = unpack("c", $this->readByte()); $d = unpack("c", $this->readByte()); return mktime(0, 0, 0, $m[1], $d[1], $y); }
function trackToFlash($id) { if (file_exists("tracks/" . $id . ".track")) { $file = fopen("tracks/" . $id . ".track", "r"); $startLine = false; $final = ""; $lineid = 0; while (ftell($file) < filesize("tracks/" . $id . ".track")) { $skipIt = false; $length = readShort($file); if ($length == 0) { if (readByte($file) == 9) { //End Array/Object $skipIt = true; if ($startLine == true) { $startLine = false; } } else { skip($file, -1); //Invalid item of length 0 $skipIt = true; } } if ($skipIt == false) { $name = readString($file, $length); $type = readByte($file); if ($type == 0) { //Double if ($startLine == true) { $append = "s"; } else { $append = "l"; } if ($name != 'level') { $val = readDouble($file); if ((string) $val == 'NAN') { $val = 'undefined'; } $final .= $append . $lineid . "_" . $name . "=" . $val . "&"; } else { skip($file, 8); } } if ($type == 1) { //Boolean (Show) skip($file, 1); } if ($type == 2) { //String $strlength = readShort($file); skip($file, $strlength); } //Type 3 & 6 Do Nothing if ($type == 8) { //Array if ($name == "startLine") { $startLine = true; } else { $lineid = (int) $name; } skip($file, 4); } } } fclose($file); $final = substr($final, 0, strlen($final) - 1); return $final; } }
function checkTTF($file) { //Check if font license allows embedding $f = fopen($file, 'rb'); if (!$f) { die('<b>Error:</b> Can\'t open ' . $file); } //Extract number of tables fseek($f, 4, SEEK_CUR); $nb = readShort($f); fseek($f, 6, SEEK_CUR); //Seek OS/2 table $found = false; for ($i = 0; $i < $nb; $i++) { if (fread($f, 4) == 'OS/2') { $found = true; break; } fseek($f, 12, SEEK_CUR); } if (!$found) { fclose($f); return; } fseek($f, 4, SEEK_CUR); $offset = readLong($f); fseek($f, $offset, SEEK_SET); //Extract fsType flags fseek($f, 8, SEEK_CUR); $fsType = readShort($f); $rl = ($fsType & 0x2) != 0; $pp = ($fsType & 0x4) != 0; $e = ($fsType & 0x8) != 0; fclose($f); if ($rl && !$pp && !$e) { echo '<b>Warning:</b> font license does not allow embedding'; } }
function clanAllyCrest($type, $id, $gsId, $crest) { $cacheTime = 3600; $path = Yii::getPathOfAlias('webroot.uploads.images.crest') . DIRECTORY_SEPARATOR . $gsId . DIRECTORY_SEPARATOR . $type; $filePath = $id . '.png'; if (!is_dir($path)) { if (!mkdir($path, 0777, TRUE)) { return ''; } } if (!is_file($path . DIRECTORY_SEPARATOR . $filePath) || time() - filemtime($path . DIRECTORY_SEPARATOR . $filePath) >= $cacheTime) { // Генерю файл $rnd_file = tmpfile(); fwrite($rnd_file, $crest); fseek($rnd_file, 0); $file =& $rnd_file; //fopen($filename,'rb'); $dds = fread($file, 4); if ($dds !== 'DDS ') { return emptyCrest(); } $hdrSize = readInt($file); $hdrFlags = readInt($file); $imgHeight = readInt($file) - 4; $imgWidth = readInt($file); $imgPitch = readShort($file); fseek($file, 84); $dxt1 = fread($file, 4); if ($dxt1 !== 'DXT1') { return emptyCrest(); } fseek($file, 128); //header ("Content-type: image/png"); $img = imagecreatetruecolor($imgWidth, $imgHeight); for ($y = -1; $y < $imgHeight / 4; $y++) { for ($x = 0; $x < $imgWidth / 4; $x++) { $color0_16 = readShort($file); $color1_16 = readShort($file); $r0 = $color0_16 >> 11 << 3; $g0 = ($color0_16 >> 5 & 63) << 2; $b0 = ($color0_16 & 31) << 3; $r1 = $color1_16 >> 11 << 3; $g1 = ($color1_16 >> 5 & 63) << 2; $b1 = ($color1_16 & 31) << 3; $color0_32 = imagecolorallocate($img, $r0, $g0, $b0); $color1_32 = imagecolorallocate($img, $r1, $g1, $b1); $color01_32 = imagecolorallocate($img, $r0 / 2 + $r1 / 2, $g0 / 2 + $g1 / 2, $b0 / 2 + $b1 / 2); $black = imagecolorallocate($img, 0, 0, 0); $data = readInt($file); for ($yy = 0; $yy < 4; $yy++) { for ($xx = 0; $xx < 4; $xx++) { $bb = $data & 3; $data = $data >> 2; switch ($bb) { case 0: $c = $color0_32; break; case 1: $c = $color1_32; break; case 2: $c = $color01_32; break; default: $c = $black; break; } imagesetpixel($img, $x * 4 + $xx, $y * 4 + $yy, $c); } } } } imagepng($img, $path . DIRECTORY_SEPARATOR . $filePath); imagedestroy($img); } return '<img src="' . app()->getBaseUrl(TRUE) . '/uploads/images/crest/' . $gsId . '/' . $type . '/' . $filePath . '">'; }
if ($value == 1) { $accelLines[$track]++; } if ($value == 2) { $backLines[$track]++; } } } } if ($type == 1) { //Boolean (Show) skip($file, 1); } if ($type == 2) { //String $strlength = readShort($file); $value = readString($file, $strlength); $trackLengthOff[$currentTrack] = ftell($file) - $trackStartOff[$currentTrack] + 3; if ($name == 'label') { $trackName[$track] = $value; break; } } if ($type == 3) { //Object $currentTrack = (int) $name; $trackStartOff[$currentTrack] = ftell($file); } // Type 6: Undefined: Do Nothing if ($type == 8) { //Array