From 48917e718e55bc4e72d2b5f928e68049c35652e5 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Wed, 19 Oct 2022 14:42:42 -0700 Subject: [PATCH] Interlace all output JPEG Progressive images are both smaller and faster to load. Signed-off-by: Varun Patil --- lib/private/legacy/OC_Image.php | 4 ++++ tests/lib/ImageTest.php | 2 ++ 2 files changed, 6 insertions(+) diff --git a/lib/private/legacy/OC_Image.php b/lib/private/legacy/OC_Image.php index a212d639084..45584b7209a 100644 --- a/lib/private/legacy/OC_Image.php +++ b/lib/private/legacy/OC_Image.php @@ -290,6 +290,8 @@ class OC_Image implements \OCP\IImage { $retVal = imagegif($this->resource, $filePath); break; case IMAGETYPE_JPEG: + /** @psalm-suppress InvalidScalarArgument */ + imageinterlace($this->resource, (PHP_VERSION_ID >= 80000 ? true : 1)); $retVal = imagejpeg($this->resource, $filePath, $this->getJpegQuality()); break; case IMAGETYPE_PNG: @@ -379,6 +381,8 @@ class OC_Image implements \OCP\IImage { $res = imagepng($this->resource); break; case "image/jpeg": + /** @psalm-suppress InvalidScalarArgument */ + imageinterlace($this->resource, (PHP_VERSION_ID >= 80000 ? true : 1)); $quality = $this->getJpegQuality(); if ($quality !== null) { $res = imagejpeg($this->resource, null, $quality); diff --git a/tests/lib/ImageTest.php b/tests/lib/ImageTest.php index e6818c7e243..c843d5f5eb9 100644 --- a/tests/lib/ImageTest.php +++ b/tests/lib/ImageTest.php @@ -149,6 +149,8 @@ class ImageTest extends \Test\TestCase { $img = new \OC_Image(null, null, $config); $img->loadFromFile(OC::$SERVERROOT.'/tests/data/testimage.jpg'); $raw = imagecreatefromstring(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg')); + /** @psalm-suppress InvalidScalarArgument */ + imageinterlace($raw, (PHP_VERSION_ID >= 80000 ? true : 1)); ob_start(); imagejpeg($raw); $expected = ob_get_clean(); -- 2.39.5