Skip to content

Commit

Permalink
Merge pull request #75 from 360fun/master
Browse files Browse the repository at this point in the history
Removed destructor after output + improved desaturate method with specifiable amount
  • Loading branch information
claviska committed Apr 8, 2015
2 parents 9ce9764 + bc04506 commit 7cdddb5
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/abeautifulsite/SimpleImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -625,10 +638,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();

}

/**
Expand Down Expand Up @@ -1267,4 +1276,4 @@ protected function normalize_color($color) {
return false;
}

}
}

0 comments on commit 7cdddb5

Please sign in to comment.