Skip to content

Commit 06339a9

Browse files
Merge pull request #132 from lefuturiste/master
add gamma correct option
2 parents e7a349b + 4526241 commit 06339a9

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,15 @@ $flip->imageFlip($image, 0);
354354

355355
Both functions will be used in the order in which they were added.
356356

357+
Gamma color correction
358+
--------
359+
360+
You can disable the gamma color correction enabled by default.
361+
362+
```php
363+
$image = new ImageResize('image.png');
364+
$image->gamma(false);
365+
```
357366

358367
API Doc
359368
-------

lib/ImageResize.php

+21-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ImageResize
2424
public $quality_webp = 85;
2525
public $quality_png = 6;
2626
public $quality_truecolor = true;
27+
public $gamma_correct = true;
2728

2829
public $interlace = 1;
2930

@@ -47,8 +48,7 @@ class ImageResize
4748
protected $source_h;
4849

4950
protected $source_info;
50-
51-
51+
5252
protected $filters = [];
5353

5454
/**
@@ -286,7 +286,9 @@ public function save($filename, $image_type = null, $quality = null, $permission
286286

287287
imageinterlace($dest_image, $this->interlace);
288288

289-
imagegammacorrect($this->source_image, 2.2, 1.0);
289+
if ($this->gamma_correct) {
290+
imagegammacorrect($this->source_image, 2.2, 1.0);
291+
}
290292

291293
if( !empty($exact_size) && is_array($exact_size) ) {
292294
if ($this->getSourceHeight() < $this->getSourceWidth()) {
@@ -312,7 +314,9 @@ public function save($filename, $image_type = null, $quality = null, $permission
312314
$this->source_h
313315
);
314316

315-
imagegammacorrect($dest_image, 1.0, 2.2);
317+
if ($this->gamma_correct) {
318+
imagegammacorrect($dest_image, 1.0, 2.2);
319+
}
316320

317321

318322
$this->applyFilter($dest_image);
@@ -756,4 +760,17 @@ public function imageFlip($image, $mode)
756760
}
757761
imagedestroy($temp_image);
758762
}
763+
764+
/**
765+
* Enable or not the gamma color correction on the image, enabled by default
766+
*
767+
* @param bool $enable
768+
* @return static
769+
*/
770+
public function gamma($enable = true)
771+
{
772+
$this->gamma_correct = $enable;
773+
774+
return $this;
775+
}
759776
}

0 commit comments

Comments
 (0)