sfImageOpacityImageMagick.class.php 1.65 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
<?php
/*
 * This file is part of the sfImageTransform package.
 * (c) 2007 Stuart <stuart.lowes@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
/**
 * sfImageOpacityImageMagick class
 *
 * Changes the opacity of an image
 *
 * @package sfImageTransform
 * @subpackage transforms
 * @author Stuard Lowes <stuart.lowes@gmail.com>
 * @author Miloslav Kmet <miloslav.kmet@gmail.com>
 *
 * @version SVN: $Id$
 */
class sfImageOpacityImageMagick extends sfImageTransformAbstract
{
  /**
   * The opacity applied to the image
   */
  protected $opacity = 1;

  /**
   * Constructor of an sfImageOpacity transformation
   *
   * @param float $opacity If greater than 1, will be divided by 100
   */
  public function __construct($opacity)
  {
    $this->setOpacity($opacity);
  }

  /**
   * sets the opacity
   * @param float $opacity Image between 0 and 1. If $opacity > 1, will be diveded by 100
   * @return void
   */
  public function setOpacity($opacity)
  {
    if (is_numeric($opacity) or is_float($opacity))
    {
      if ($opacity <= 1)
      {
        $this->opacity  = $opacity;
      }

      else
      {
        $this->opacity = $opacity/100;
      }
    }
  }

  /**
   * returns the current opacity
   *
   * @return float opacity
   */
  public function getOpacity()
  {
    return $this->opacity;
  }

  /**
   * Apply the opacity transformation to the sfImage object
   *
   * @param sfImage
   *
   * @return sfImage
   */
  protected function transform(sfImage $image)
  {
    $image->getAdapter()->getHolder()->setImageOpacity($this->getOpacity());

    return $image;
  }
}