sfImageCropImageMagick.class.php 2.87 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?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.
 */

/**
 *
 * sfImageCropImageMagick class.
 *
 * Crops image.
 *
 * This class crops a image to a set size.
 *
 * @package sfImageTransform
 * @subpackage transforms
 * @author Stuart Lowes <stuart.lowes@gmail.com>
 * @version SVN: $Id$
 */
class sfImageCropImageMagick extends sfImageTransformAbstract
{
  /**
   * Left coordinate.
  */
  protected $left = 0;

  /**
   * Top coordinate
  */
  protected $top = 0;

  /**
   * Cropped area width.
  */
  protected $width;

  /**
   * Cropped area height
  */
  protected $height;

  /**
   * Construct an sfImageCrop object.
   *
   * @param integer
   * @param integer
   * @param integer
   * @param integer
   */
  public function __construct($left, $top, $width, $height)
  {
    $this->setLeft($left);
    $this->setTop($top);
    $this->setWidth($width);
    $this->setHeight($height);
  }

  /**
   * Sets the left coordinate
   *
   * @param integer
   */
  public function setLeft($left)
  {
    if (is_numeric($left))
    {
      $this->left = (int)$left;

      return true;
    }

    return false;
  }

  /**
   * returns the left coordinate
   *
   * @return integer
   */
  public function getLeft()
  {
    return $this->left;
  }

  /**
   * set the top coordinate.
   *
   * @param integer
   */
  public function setTop($top)
  {
    if (is_numeric($top))
    {
      $this->top = (int)$top;

      return true;
    }

    return false;
  }

  /**
   * returns the top coordinate
   *
   * @return integer
   */
  public function getTop()
  {
    return $this->top;
  }

  /**
   * set the width.
   *
   * @param integer
   */
  public function setWidth($width)
  {
    if (is_numeric($width))
    {
      $this->width = (int)$width;

      return true;
    }

    return false;
  }

  /**
   * returns the width of the thumbnail
   *
   * @return integer
   */
  public function getWidth()
  {
    return $this->width;
  }

  /**
   * set the height.
   *
   * @param integer
   */
  public function setHeight($height)
  {
    if (is_numeric($height))
    {
      $this->height = (int)$height;

      return true;
    }

    return false;
  }

  /**
   * returns the height of the thumbnail
   *
   * @return integer
   */
  public function getHeight()
  {
    return $this->height;
  }

  /**
   * Apply the transform to the sfImage object.
   *
   * @access protected
   * @param sfImage
   * @return sfImage
   */
  protected function transform(sfImage $image)
  {
    $resource = $image->getAdapter()->getHolder();
    $resource->cropImage($this->getWidth(), $this->getHeight(), $this->getLeft(), $this->getTop());
    $resource->setImagePage($this->getWidth(), $this->getHeight(), 0, 0);

    return $image;
  }
}