Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Grayscale thumbs #42

Merged
merged 2 commits into from

2 participants

@sebastianberns

Hello— I added the option for thumbnails to be converted to grayscale!

@bastianallgeier bastianallgeier merged commit 3181c3e into bastianallgeier:master
@bastianallgeier

That's really cool!!!!!!!

@sebastianberns sebastianberns deleted the unknown repository branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 18, 2013
  1. @sebastianberns
  2. @sebastianberns
This page is out of date. Refresh to see the latest.
Showing with 20 additions and 6 deletions.
  1. +10 −5 plugins/thumb/readme.mdown
  2. +10 −1 plugins/thumb/thumb.php
View
15 plugins/thumb/readme.mdown
@@ -15,11 +15,12 @@ Put the thumb.php file in your site/plugins folder. Add the plugins folder if it
or a more extended version:
thumb($image, array(
- 'width' => 200,
- 'height' => 200,
- 'quality' => 90,
- 'upscale' => true,
- 'crop' => true,
+ 'width' => 200,
+ 'height' => 200,
+ 'quality' => 90,
+ 'upscale' => true,
+ 'crop' => true,
+ 'grayscale' => true
));
## Available options
@@ -44,6 +45,10 @@ If this is set to true, images will be upscaled to the maximum height or width.
Set this to true to crop the image to the given width and height. Upscale is true by default in this case.
+### grayscale
+
+If set to true RGB images will be converted to grayscale
+
## Available settings
You can add the following config variables to your config file (site/config/config.php) to adjust the default settings of the thumb plugin:
View
11 plugins/thumb/thumb.php
@@ -24,6 +24,7 @@ class thumb {
var $quality = 100;
var $alt = false;
var $crop = false;
+ var $grayscale = false;
function __construct($image, $options=array()) {
@@ -48,7 +49,10 @@ function __construct($image, $options=array()) {
// set the quality
$this->crop = @$options['crop'];
-
+
+ // set the quality
+ $this->grayscale = @$options['grayscale'];
+
// set the quality
$this->quality = a::get($options, 'quality', c::get('thumb.quality', 100));
@@ -87,6 +91,7 @@ function filename() {
$options .= ($this->maxHeight) ? '.' . $this->maxHeight : '.' . 0;
$options .= ($this->upscale) ? '.' . $this->upscale : '.' . 0;
$options .= ($this->crop) ? '.' . $this->crop : '.' . 0;
+ $options .= ($this->grayscale) ? '.' . $this->grayscale : '.' . 0;
$options .= '.' . $this->quality;
return md5($this->source) . $options . '.' . $this->obj->extension;
@@ -246,6 +251,10 @@ function create() {
imagefill($thumb, 0, 0, $color);
imagecopyresampled($thumb, $image, 0, 0, 0, 0, $this->width, $this->height, $this->sourceWidth, $this->sourceHeight);
}
+
+ if($this->grayscale == true) {
+ imagefilter($thumb, IMG_FILTER_GRAYSCALE);
+ }
switch($this->mime) {
case 'image/jpeg': imagejpeg($thumb, $file, $this->quality); break;
Something went wrong with that request. Please try again.