Example #1
0
     throw new Exception('Images not found - Either you didn\'t upload any or your session expired');
 }
 $padding = isset($_REQUEST['padding']) ? (int) $_REQUEST['padding'] : 3;
 $padding = min(max(0, $padding), 25);
 $type = 'png';
 if (!empty($_REQUEST['output_type']) && in_array($_REQUEST['output_type'], ['jpeg', 'gif'])) {
     $type = $_REQUEST['output_type'];
 }
 $reduceArtefacts = !empty($_REQUEST['jpeg_reduce_artefacts']) && $type == 'jpeg';
 $prefix = '.';
 if (!empty($_REQUEST['css_prefix'])) {
     $prefix .= preg_replace('/[^a-z0-9_-]/ui', '', $_REQUEST['css_prefix']);
 }
 $s = new CssSprite($padding, $reduceArtefacts, $prefix);
 $s->addDirectory($dir);
 $s->pack();
 $options = [];
 if ($type == 'jpeg' && isset($_REQUEST['jpeg_quality'])) {
     $options = [min(100, max(0, (int) $_REQUEST['jpeg_quality']))];
 } elseif ($type == 'png') {
     $options = [9, PNG_ALL_FILTERS];
 }
 $filepath = 'uploads/' . $token . '.' . $type;
 file_put_contents($filepath, $s->getImage($type, $options));
 $server = $_SERVER['HTTP_HOST'] == 'localhost:96' ? 'dev.justsayplease.co.uk:96' : $_SERVER['HTTP_HOST'];
 $response->url = 'http://' . $server . dirname($_SERVER['PHP_SELF']) . '/uploads/' . $token . '.' . $type;
 $response->css = $s->getCss();
 //$s->smush($filepath, $response->url);
 $oldSize = 0;
 $response->info = [];
 foreach ($s->getInfo() as $image) {