sfImageGammaGD.class.php 1.96 KB
Newer Older
Яков's avatar
first  
Яков committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/*
 * This file is part of the sfImageTransform package.
 * (c) 2007 Stuart Lowes <stuart.lowes@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 *
 * sfImageGammaGD class.
 *
 * Apply a gamma correction to a GD image.
 *
 * @package sfImageTransform
 * @subpackage transforms
 * @author Stuart Lowes <stuart.lowes@gmail.com>
 * @version SVN: $Id$
 */
class sfImageGammaGD extends sfImageTransformAbstract
{
  /**
   * The input gamma.
   * @var float
  */
  protected $input_gamma = 1.0;

  /**
   * The number of pixels used for the blur.
   * @var float
  */
  protected $output_gamma = 1.6;

  /**
   * Construct an sfImageGamma object.
   *
   * @param float
   * @param float
   */
  public function __construct($input_gamma=1.0, $output_gamma=1.6)
  {
    $this->setInputGamma($input_gamma);
    $this->setOutputGamma($output_gamma);
  }

  /**
   * Sets the input gamma
   *
   * @param float
   * @return boolean
   */
  public function setInputGamma($gamma)
  {
    if (is_float($gamma))
    {
      $this->input_gamma = (float)$gamma;

      return true;
    }

    return false;
  }

  /**
   * Gets the input gamma
   *
   * @return integer
   */
  public function getInputGamma()
  {
    return $this->input_gamma;
  }

  /**
   * Sets the ouput gamma
   *
   * @param float
   */
  public function setOutputGamma($gamma)
  {
    if (is_numeric($gamma))
    {
      $this->ouput_gamma = (float)$gamma;

      return true;
    }
  }

  /**
   * Gets the ouput gamma
   *
   * @return integer
   */
  public function getOuputGamma()
  {
    return $this->ouput_gamma;
  }

  /**
   * Apply the transform to the sfImage object.
   *
   * @param sfImage
   * @return sfImage
   */
  protected function transform(sfImage $image)
  {
    $resource = $image->getAdapter()->getHolder();
    imagegammacorrect ($resource, $this->input_gamma, $this->output_gamma);

    return $image;
  }
}