Skip to content

Commit df695ff

Browse files
authored
add gamma correct option
With a new option on the main class, we will able to tell if we want gamma correction. When you use this library and rescale a image, the image's colors tends to not be keeped, this is caused by the image gamma correction applied before and after the proccessing.
1 parent e7a349b commit df695ff

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/ImageResize.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class ImageResize
4747
protected $source_h;
4848

4949
protected $source_info;
50-
50+
51+
protected $gamma_correct = true;
5152

5253
protected $filters = [];
5354

@@ -286,7 +287,9 @@ public function save($filename, $image_type = null, $quality = null, $permission
286287

287288
imageinterlace($dest_image, $this->interlace);
288289

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

291294
if( !empty($exact_size) && is_array($exact_size) ) {
292295
if ($this->getSourceHeight() < $this->getSourceWidth()) {
@@ -312,7 +315,9 @@ public function save($filename, $image_type = null, $quality = null, $permission
312315
$this->source_h
313316
);
314317

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

317322

318323
$this->applyFilter($dest_image);

0 commit comments

Comments
 (0)