00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Varien_Image
00035 {
00036 protected $_adapter;
00037
00038 protected $_fileName;
00039
00040
00041
00042
00043
00044
00045
00046
00047 function __construct($fileName=null, $adapter=Varien_Image_Adapter::ADAPTER_GD2)
00048 {
00049 $this->_getAdapter($adapter);
00050 $this->_fileName = $fileName;
00051 if( isset($fileName) ) {
00052 $this->open();
00053 }
00054 }
00055
00056
00057
00058
00059
00060
00061
00062 public function open()
00063 {
00064 $this->_getAdapter()->checkDependencies();
00065
00066 if( !file_exists($this->_fileName) ) {
00067 throw new Exception("File '{$this->_fileName}' does not exists.");
00068 }
00069
00070 $this->_getAdapter()->open($this->_fileName);
00071 }
00072
00073
00074
00075
00076
00077
00078
00079 public function display()
00080 {
00081 $this->_getAdapter()->display();
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 public function save($destination=null, $newFileName=null)
00093 {
00094 $this->_getAdapter()->save($destination, $newFileName);
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104 public function rotate($angle)
00105 {
00106 $this->_getAdapter()->rotate($angle);
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 public function crop($top=0, $left=0, $right=0, $bottom=0)
00120 {
00121 $this->_getAdapter()->crop($left, $top, $right, $bottom);
00122 }
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 public function resize($width, $height = null)
00133 {
00134 $this->_getAdapter()->resize($width, $height);
00135 }
00136
00137 public function keepAspectRatio($value)
00138 {
00139 return $this->_getAdapter()->keepAspectRatio($value);
00140 }
00141
00142 public function keepFrame($value)
00143 {
00144 return $this->_getAdapter()->keepFrame($value);
00145 }
00146
00147 public function keepTransparency($value)
00148 {
00149 return $this->_getAdapter()->keepTransparency($value);
00150 }
00151
00152 public function constrainOnly($value)
00153 {
00154 return $this->_getAdapter()->constrainOnly($value);
00155 }
00156
00157 public function backgroundColor($value)
00158 {
00159 return $this->_getAdapter()->backgroundColor($value);
00160 }
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 public function watermark($watermarkImage, $positionX=0, $positionY=0, $watermarkImageOpacity=30, $repeat=false)
00175 {
00176 if( !file_exists($watermarkImage) ) {
00177 throw new Exception("Required file '{$watermarkImage}' does not exists.");
00178 }
00179 $this->_getAdapter()->watermark($watermarkImage, $positionX, $positionY, $watermarkImageOpacity, $repeat);
00180 }
00181
00182
00183
00184
00185
00186
00187
00188 public function getMimeType()
00189 {
00190 return $this->_getAdapter()->getMimeType();
00191 }
00192
00193
00194
00195
00196
00197
00198
00199 public function process()
00200 {
00201
00202 }
00203
00204
00205
00206
00207
00208
00209
00210 public function instruction()
00211 {
00212
00213 }
00214
00215
00216
00217
00218
00219
00220
00221
00222 public function setImageBackgroundColor($color)
00223 {
00224 $this->_getAdapter()->imageBackgroundColor = intval($color);
00225 }
00226
00227 public function setWatermarkPosition($position)
00228 {
00229 $this->_getAdapter()->setWatermarkPosition($position);
00230 return $this;
00231 }
00232
00233 public function setWatermarkWidth($width)
00234 {
00235 $this->_getAdapter()->setWatermarkWidth($width);
00236 return $this;
00237 }
00238
00239 public function setWatermarkHeigth($heigth)
00240 {
00241 $this->_getAdapter()->setWatermarkHeigth($heigth);
00242 return $this;
00243 }
00244
00245
00246
00247
00248
00249
00250
00251 protected function _getAdapter($adapter=null)
00252 {
00253 if( !isset($this->_adapter) ) {
00254 $this->_adapter = Varien_Image_Adapter::factory( $adapter );
00255 }
00256 return $this->_adapter;
00257 }
00258
00259
00260
00261
00262
00263
00264 public function getOriginalWidth()
00265 {
00266 return $this->_getAdapter()->getOriginalWidth();
00267 }
00268
00269
00270
00271
00272
00273
00274 public function getOriginalHeight()
00275 {
00276 return $this->_getAdapter()->getOriginalHeight();
00277 }
00278 }