Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

+imageFilter: simple wrapper for GD function #39

Merged
merged 2 commits into from

4 participants

@inalyricalcoma

simple wrapper for GD function, so we can use filters via http://php.net/manual/en/function.imagefilter.php

thanks for you work!

@gtraxx

How do I use filtered to have a black and white for example?
Can we make a simple plugin to transform a black and white using filter?
Best regards

@inalyricalcoma

if you need a grayscale image as output, you can do:

$thumb->imageFilter(IMG_FILTER_GRAYSCALE);

where $thumb is your PhpThumb object :)

ofc, your server needs to be able to use imageFilters, there's a note in php docs:
This function is only available if PHP is compiled with the bundled version of the GD library.

which, incidentally, i discovered by myself today D:

@gtraxx

thank you, I commented on my ticket about creating a plugin.
It is finished and being tested :)
see my ticket : #51

@masterexploder masterexploder merged commit 42b7524 into masterexploder:master
@stephencozart

Nice work!! I had actually just created a plugin to do just this but It's nice to have it in the source code. Should of checked here first :)

@gtraxx

Hello I also created a plugin to do tha
t and more, which turns black and white, sepia, customization
How to mail it in via my github account?
I discover github :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 35 additions and 0 deletions.
  1. +35 −0 src/GdThumb.inc.php
View
35 src/GdThumb.inc.php
@@ -840,6 +840,41 @@ public function rotateImageNDegrees ($degrees)
}
/**
+ * Applies a filter to the image
+ *
+ * @param int $filter
+ * @return GdThumb
+ */
+ public function imageFilter ($filter, $arg1 = false, $arg2 = false, $arg3 = false, $arg4 = false)
+ {
+ if (!is_numeric($filter))
+ {
+ throw new InvalidArgumentException('$filter must be numeric');
+ }
+
+ if (!function_exists('imagefilter'))
+ {
+ throw new RuntimeException('Your version of GD does not support image filters.');
+ }
+
+ $result = false;
+ if ( $arg1 === false ) $result = imagefilter($this->oldImage, $filter);
+ else if ( $arg2 === false ) $result = imagefilter($this->oldImage, $filter, $arg1);
+ else if ( $arg3 === false ) $result = imagefilter($this->oldImage, $filter, $arg1, $arg2);
+ else if ( $arg4 === false ) $result = imagefilter($this->oldImage, $filter, $arg1, $arg2, $arg3);
+ else $result = imagefilter($this->oldImage, $filter, $arg1, $arg2, $arg3, $arg4);
+
+ if (!$result)
+ {
+ throw new RuntimeException('GD imagefilter failed');
+ }
+
+ $this->workingImage = $this->oldImage;
+
+ return $this;
+ }
+
+ /**
* Shows an image
*
* This function will show the current image by first sending the appropriate header
Something went wrong with that request. Please try again.