$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) { $response->info[] = ['file' => $image['pathInfo']['basename'], 'x' => $image['x'], 'y' => $image['y'], 'width' => $image['width'], 'height' => $image['height'], 'class' => $image['class'], 'selector' => $image['selector'], 'css' => $image['css']]; $oldSize += filesize($image['path']); } $response->oldSize = $oldSize; $response->newSize = filesize($filepath); $info = getimagesize($filepath); $response->width = $info[0]; $response->height = $info[1];