From 54462c777fc5f7412f402570a59813df9dfd5df0 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Fri, 1 Mar 2013 21:06:06 +0100 Subject: [PATCH] added quality param for png format --- src/Intervention/Image/Image.php | 7 ++++++- tests/ImageTest.php | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Intervention/Image/Image.php b/src/Intervention/Image/Image.php index 3336cfd3..234ad621 100644 --- a/src/Intervention/Image/Image.php +++ b/src/Intervention/Image/Image.php @@ -666,6 +666,10 @@ class Image */ private function data($type = null, $quality = 90) { + if ($quality < 0 || $quality > 100) { + throw new Exception('Quality of image must range from 0 to 100.'); + } + ob_start(); switch (strtolower($type)) { @@ -674,9 +678,10 @@ class Image break; case 'png': + $quality = round($quality / 11.11111111111); // transform quality to png setting @imagealphablending($this->resource, false); @imagesavealpha($this->resource, true); - @imagepng($this->resource); + @imagepng($this->resource, null, $quality); break; default: diff --git a/tests/ImageTest.php b/tests/ImageTest.php index f35e42c2..6bd0506b 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -335,6 +335,18 @@ class ImageTest extends PHPUnit_Framework_Testcase $img->save($save_as); $this->assertFileExists($save_as); @unlink($save_as); + + $save_as = 'public/test2.png'; + $img = $this->getTestImage(); + $img->save($save_as, 80); + $this->assertFileExists($save_as); + @unlink($save_as); + + $save_as = 'public/test2.jpg'; + $img = $this->getTestImage(); + $img->save($save_as, 0); + $this->assertFileExists($save_as); + @unlink($save_as); } public function testStringConversion()