diff --git a/.travis.yml b/.travis.yml index af3b60b..86b70c3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,9 +22,7 @@ before_install: - sudo service docker start - docker --version - docker buildx create --use - -install: -- docker-compose build +- docker-compose up -d script: -- docker-compose up \ No newline at end of file +- docker compose exec php8 /code/vendor/bin/phpunit --configuration /code/phpunit.xml $@ \ No newline at end of file diff --git a/Dockerfile-php8 b/Dockerfile-php8 index f8599b1..4441358 100644 --- a/Dockerfile-php8 +++ b/Dockerfile-php8 @@ -64,4 +64,4 @@ COPY ./psalm.xml /code/psalm.xml RUN echo extension=imagick.so >> /usr/local/etc/php/conf.d/imagick.ini -CMD [ "sh", "-c", "/code/vendor/bin/phpunit --verbose --configuration /code/phpunit.xml && /code/vendor/bin/psalm --show-info=true" ] \ No newline at end of file +CMD [ "tail", "-f", "/dev/null" ] diff --git a/src/Image/Image.php b/src/Image/Image.php index 78ada31..fb47214 100644 --- a/src/Image/Image.php +++ b/src/Image/Image.php @@ -360,7 +360,6 @@ public function save(string $path = null, string $type = '', int $quality = 75) case 'jpg': case 'jpeg': $this->image->setImageCompressionQuality($quality); - $this->image->setImageFormat('jpg'); break; @@ -370,6 +369,7 @@ public function save(string $path = null, string $type = '', int $quality = 75) case 'webp': try { + $this->image->setImageCompressionQuality($quality); $this->image->setImageFormat('webp'); } catch (\Throwable$th) { $signature = $this->image->getImageSignature(); @@ -406,12 +406,10 @@ public function save(string $path = null, string $type = '', int $quality = 75) case 'png': /* Scale quality from 0-100 to 0-9 */ $scaleQuality = \round(($quality / 100) * 9); - /* Invert quality setting as 0 is best, not 9 */ $invertScaleQuality = intval(9 - $scaleQuality); $this->image->setImageCompressionQuality($invertScaleQuality); - $this->image->setImageFormat('png'); break; diff --git a/tests/Image/100x100-q30.webp b/tests/Image/100x100-q30.webp new file mode 100644 index 0000000..7bda00f Binary files /dev/null and b/tests/Image/100x100-q30.webp differ diff --git a/tests/Image/ImageTest.php b/tests/Image/ImageTest.php index 18ea6e2..f502bb6 100644 --- a/tests/Image/ImageTest.php +++ b/tests/Image/ImageTest.php @@ -286,6 +286,34 @@ public function testCrop100x100WEBP(): void \unlink($target); } + public function testCrop100x100WEBPQuality30(): void + { + $image = new Image(\file_get_contents(__DIR__.'/../resources/disk-a/kitten-1.jpg') ?: ''); + $target = __DIR__.'/100x100-q30.webp'; + $original = __DIR__.'/../resources/resize/100x100-q30.webp'; + + $image->crop(100, 100); + + $image->save($target, 'webp', 30); + + $this->assertEquals(\is_readable($target), true); + $this->assertGreaterThan(500, \filesize($target)); + $this->assertLessThan(2000, \filesize($target)); + $this->assertEquals(\mime_content_type($target), \mime_content_type($original)); + $this->assertNotEmpty(\md5(\file_get_contents($target) ?: '')); + + $this->assertEquals(\is_readable($target), true); + $this->assertNotEmpty(\md5(\file_get_contents($target) ?: '')); + + $image = new \Imagick($target); + + $this->assertEquals(100, $image->getImageWidth()); + $this->assertEquals(100, $image->getImageHeight()); + $this->assertTrue(in_array($image->getImageFormat(), ['PAM', 'WEBP'])); + + //\unlink($target); + } + public function testCrop100x100PNG(): void { $image = new Image(\file_get_contents(__DIR__.'/../resources/disk-a/kitten-1.jpg') ?: ''); diff --git a/tests/resources/resize/100x100-q30.webp b/tests/resources/resize/100x100-q30.webp new file mode 100644 index 0000000..7bda00f Binary files /dev/null and b/tests/resources/resize/100x100-q30.webp differ diff --git a/tests/resources/resize/C.jpg b/tests/resources/resize/C.jpg index 1565b86..3086e41 100644 Binary files a/tests/resources/resize/C.jpg and b/tests/resources/resize/C.jpg differ diff --git a/tests/resources/resize/N.gif b/tests/resources/resize/N.gif index b72a7a6..edb8159 100644 Binary files a/tests/resources/resize/N.gif and b/tests/resources/resize/N.gif differ diff --git a/tests/resources/resize/S.gif b/tests/resources/resize/S.gif index e1a8598..bb63e0b 100644 Binary files a/tests/resources/resize/S.gif and b/tests/resources/resize/S.gif differ diff --git a/tests/resources/resize/W.gif b/tests/resources/resize/W.gif index efafc60..3ddf8c2 100644 Binary files a/tests/resources/resize/W.gif and b/tests/resources/resize/W.gif differ