thumb: strip metadata and chroma
[minimedit.git] / thumb / index.php
index 27a194ee51584f5840c42eff880207e02e6a42da..d296fbf1560e0f4d339912fa7e9aa6f8c5f575b9 100644 (file)
@@ -1,6 +1,4 @@
 <?php
-ob_clean();
-
 list ($size, $imgpath) = explode('/', ltrim($Args, '/'), 2);
 $imgpath = preg_replace('{^(?=[0-9]+/)}', 'data/', $imgpath, 1);
 
@@ -28,6 +26,7 @@ catch (Throwable $e) {
        exit;
 }
 
+header('Cache-Control: max-age=2628000');
 header('Content-type: '.mime_content_type($target));
 readfile($target);
 exit;
@@ -88,9 +87,14 @@ function mkthumb_exec($source, $target, $width, $height)
        }
        $cmd = implode(' ', array_map('escapeshellarg', [
                'convert',
+               '-delete', '1--1', # static
                '-trim',
+               '-background', 'white', '-layers', 'flatten', # opaque
+               '-interlace', 'plane', # progressive
+               '-strip', '-taint', # omit metadata
+               '-sampling-factor', '4:2:0', '-colorspace', 'sRGB', # half chroma
                '-resize', "${width}x${height}",
-               '-quality', '90%',
+               '-quality', '85%',
                $source, "jpg:$target"
        ]));
        $return = shell_exec("$cmd 2>&1");