1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-20 12:41:23 +02:00

added quality param for png format

This commit is contained in:
Oliver Vogel
2013-03-01 21:06:06 +01:00
parent 291a13927b
commit 54462c777f
2 changed files with 18 additions and 1 deletions

View File

@@ -666,6 +666,10 @@ class Image
*/ */
private function data($type = null, $quality = 90) 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(); ob_start();
switch (strtolower($type)) { switch (strtolower($type)) {
@@ -674,9 +678,10 @@ class Image
break; break;
case 'png': case 'png':
$quality = round($quality / 11.11111111111); // transform quality to png setting
@imagealphablending($this->resource, false); @imagealphablending($this->resource, false);
@imagesavealpha($this->resource, true); @imagesavealpha($this->resource, true);
@imagepng($this->resource); @imagepng($this->resource, null, $quality);
break; break;
default: default:

View File

@@ -335,6 +335,18 @@ class ImageTest extends PHPUnit_Framework_Testcase
$img->save($save_as); $img->save($save_as);
$this->assertFileExists($save_as); $this->assertFileExists($save_as);
@unlink($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() public function testStringConversion()