From 0a4c4d5024c8efd6ede6079718bb9b0ae8eeba72 Mon Sep 17 00:00:00 2001 From: Francesco Marino Date: Wed, 8 Apr 2015 12:27:58 +0200 Subject: [PATCH 1/2] Update SimpleImage.php I suggest to don't destroy the object after the output, in this way is still possible modify the image object and save several other different images: I had a situation in which I needed to show the resized version and save it, but right after that add a desaturation filter and save a second image without showing it (normal button + hover status). --- src/abeautifulsite/SimpleImage.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/abeautifulsite/SimpleImage.php b/src/abeautifulsite/SimpleImage.php index 290010a..209ccb7 100644 --- a/src/abeautifulsite/SimpleImage.php +++ b/src/abeautifulsite/SimpleImage.php @@ -625,10 +625,6 @@ function output($format = null, $quality = null) { throw new Exception('Unsupported image format: '.$this->filename); break; } - - // Since no more output can be sent, call the destructor to free up memory - $this->__destruct(); - } /** @@ -1267,4 +1263,4 @@ protected function normalize_color($color) { return false; } -} \ No newline at end of file +} From bc0450630e4f86a998632ecf5cec7cc0b4ec79fd Mon Sep 17 00:00:00 2001 From: Francesco Marino Date: Wed, 8 Apr 2015 12:41:36 +0200 Subject: [PATCH 2/2] Update SimpleImage.php Improved the desaturate function with a specifiable amount (0-1) --- src/abeautifulsite/SimpleImage.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/abeautifulsite/SimpleImage.php b/src/abeautifulsite/SimpleImage.php index 209ccb7..ca34e7d 100644 --- a/src/abeautifulsite/SimpleImage.php +++ b/src/abeautifulsite/SimpleImage.php @@ -309,13 +309,26 @@ function crop($x1, $y1, $x2, $y2) { } /** - * Desaturate (grayscale) + * Desaturate (grayscale if nothing specified) * * @return SimpleImage * */ - function desaturate() { - imagefilter($this->image, IMG_FILTER_GRAYSCALE); + function desaturate($amount=1) { + // Determine amount + $amount = $this->keep_within($amount, 0, 1) * 100; + + // Make a desaturated copy of the image + $new = imagecreatetruecolor($this->width, $this->height); + imagealphablending($new, false); + imagesavealpha($new, true); + imagecopy($new, $this->image, 0, 0, 0, 0, $this->width, $this->height); + imagefilter($new, IMG_FILTER_GRAYSCALE); + + // Merge with specified amount + $this->imagecopymerge_alpha($this->image, $new, 0, 0, 0, 0, $this->width, $this->height, $amount); + imagedestroy($new); + return $this; }