Example #1
0
     $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];
 } elseif (isset($_REQUEST['cleanup'])) {
     if (isset($_REQUEST['token'])) {
         if (preg_match('/^[a-z0-9]+$/i', $_REQUEST['token'])) {
             deleteDir('uploads/u-' . $_REQUEST['token']);
             foreach (glob('uploads/u-' . $_REQUEST['token'] . '.*') as $file) {
                 unlink($file);
             }