From e471063c378ca80ce1415f04335d41dd3d5da6f9 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Fri, 1 Feb 2013 18:19:12 +0100 Subject: [PATCH] added quality parameter --- README.md | 3 +++ src/Intervention/Image/Image.php | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 87b1a403..df1d02e9 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,9 @@ $img->pixelate(25); // save image in desired format $img->save('public/bar.jpg'); +// save image in desired format and quality +$img->save('public/bar.jpg', 60); + // its also possible to chain methods $img1 = Image::make('public/img1.png'); $img2 = Image::make('public/img2.png'); diff --git a/src/Intervention/Image/Image.php b/src/Intervention/Image/Image.php index c6a57a4e..0ef3e497 100644 --- a/src/Intervention/Image/Image.php +++ b/src/Intervention/Image/Image.php @@ -387,10 +387,11 @@ class Image /** * Returns image type stream * - * @param string $type gif|png|jpg|jpeg + * @param string $type gif|png|jpg|jpeg + * @param integer quality * @return string */ - private function data($type = null) + private function data($type = null, $quality = 90) { ob_start(); @@ -406,7 +407,7 @@ class Image default: case 'jpg': case 'jpeg': - @imagejpeg($this->resource, null, 90); + @imagejpeg($this->resource, null, $quality); break; } @@ -456,10 +457,10 @@ class Image * @param string $path * @return Image */ - public function save($path = null) + public function save($path = null, $quality = 90) { $path = is_null($path) ? ($this->dirname .'/'. $this->basename) : $path; - file_put_contents($path, $this->data($this->filesystem->extension($path))); + file_put_contents($path, $this->data($this->filesystem->extension($path), $quality)); return $this; }