/** * @dataProvider dataProvider */ public function testJs2Php($input) { $this->open($this->browserPath); $this->type('toCompress', $input); $this->click('compress'); $decompressed = \LZString::decompressFromBase64($this->getValue('compressed')); $this->assertEquals($input, $decompressed); }
<tr> <th>Value</th> <th>Compressed</th> <th>PHP</th> <th>JS</th> <th>MATCH</th> </tr> </thead> <tbody class="decompressFromBase64"> <?php foreach ($set as $value) { echo ' <tr> <td class="value">' . $value . '</td> <td class="compressed">' . LZString::compressToBase64($value) . '</td> <td class="PHP">' . LZString::decompressFromBase64(LZString::compressToBase64($value)) . '</td> <td class="JS"></td> <td class="equals"></td> </tr> '; } ?> </tbody> </table> </div> <hr> </div> <div class="row"> <div class="col-lg-6"> <h2>php/js fromCharCode</h2> <table class="table table-striped table-condensed">
header("Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With"); header("Access-Control-Allow-Credentials: true"); header("Content-Type: application/json"); // Process Upload $raw = file_get_contents("php://input"); $json = json_decode($raw); if (!isset($json->moduleId) || is_null($json->moduleId) || (!isset($json->sessionId) || is_null($json->sessionId)) || (!isset($json->userCode) || is_null($json->userCode))) { header('HTTP/1.1 500 Internal Server Error'); echo json_decode("{'message': 'Missing data!'}"); exit; } $user = filter_var($json->userCode, FILTER_SANITIZE_STRING); $moduleId = filter_var($json->moduleId, FILTER_SANITIZE_STRING); $moduleLabel = filter_var($json->moduleLabel, FILTER_SANITIZE_STRING); $sessionId = str_pad($json->sessionId, 6, "0", STR_PAD_LEFT); $data = LZString::decompressFromBase64($json->trialData); $path = $tatoolwebpath . $moduleId . "/"; $filename = (is_null($moduleLabel) ? $moduleId : $moduleLabel) . "_" . $user . "_" . $sessionId; $zipFilename = $moduleId . "_" . $user . '.zip'; $timestamp = ""; $extension = ".csv"; // create target module directory if it doesn't exist yet if (!file_exists($path)) { mkdir($path, 0777, true); } // check if file already exists and append timestamp if it does if (file_exists($path . $filename . $extension)) { $timestamp = "_" . time(); } // write file try {
<?php require 'LZString.php'; $imagePath = 'images/test.bmp'; $paletteKey = 'test.palette'; $pendingTasksKey = 'test.pending'; $data = LZString::decompressFromBase64($_POST['data']); $json = json_decode($data, true); $taskId = $json['taskId']; $x = $json['x']; $y = $json['y']; $columns = $json['columns']; $rows = $json['rows']; $solution = $json['solution']; $image = new Imagick($imagePath); $areaIterator = $image->getPixelRegionIterator($x, $y, $columns, $rows); $index = 0; $bool = true; $colorPalette = apc_fetch($paletteKey, $bool); foreach ($areaIterator as $rowIterator) { foreach ($rowIterator as $pixel) { $nearestPoint = $solution[$index]; $index += 1; if ($nearestPoint != -1) { $color = $colorPalette[$nearestPoint]; $pixel->setColor(sprintf("rgb(%s, %s, %s)", $color['r'], $color['g'], $color['b'])); } else { $pixel->setColor("rgb(0, 0, 0)"); //pixel is already black } }