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:
@@ -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:
|
||||||
|
@@ -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()
|
||||||
|
Reference in New Issue
Block a user