Permalink
Browse files

Implementing sharpen effect

  • Loading branch information...
1 parent edc2e77 commit d70b753e3a432e386a06a8862e435e9fee346e23 @hisamu hisamu committed Jan 25, 2013
View
9 lib/Imagine/Effects/EffectsInterface.php
@@ -57,4 +57,13 @@ public function grayscale();
* @throws RuntimeException
*/
public function colorize(Color $color);
+
+ /**
+ * Sharpens the image
+ *
+ * @return EffectsInterface
+ *
+ * @throws RuntimeException
+ */
+ public function sharpen();
}
View
15 lib/Imagine/Gd/Effects.php
@@ -74,4 +74,19 @@ public function colorize(Color $color)
return $this;
}
+
+ /**
+ * {@inheritdoc}
+ */
+ public function sharpen()
+ {
+ $sharpenMatrix = array(array(-1,-1,-1), array(-1,16,-1), array(-1,-1,-1));
+ $divisor = array_sum(array_map('array_sum', $sharpenMatrix));
+
+ if (false === imageconvolution($this->resource, $sharpenMatrix, $divisor, 0)) {
+ throw new RuntimeException('Failed to sharpen the image');
+ }
+
+ return $this;
+ }
}
View
8 lib/Imagine/Gmagick/Effects.php
@@ -81,4 +81,12 @@ public function colorize(Color $color)
{
throw new RuntimeException('Gmagick does not support colorize');
}
+
+ /**
+ * {@inheritdoc}
+ */
+ public function sharpen(Color $color)
+ {
+ throw new RuntimeException('Gmagick does not support sharpen yet');
+ }
}
View
14 lib/Imagine/Imagick/Effects.php
@@ -82,4 +82,18 @@ public function colorize(Color $color)
return $this;
}
+
+ /**
+ * {@inheritdoc}
+ */
+ public function sharpen()
+ {
+ try {
+ $this->imagick->sharpenImage(2, 1);
+ } catch (\ImagickException $e) {
+ throw new RuntimeException('Failed to sharpen the image');
+ }
+
+ return $this;
+ }
}

0 comments on commit d70b753

Please sign in to comment.