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 abstract class Varien_Image_Adapter_Abstract
00033 {
00034 public $fileName = null;
00035 public $imageBackgroundColor = 0;
00036
00037 const POSITION_TOP_LEFT = 'top-left';
00038 const POSITION_TOP_RIGHT = 'top-right';
00039 const POSITION_BOTTOM_LEFT = 'bottom-left';
00040 const POSITION_BOTTOM_RIGHT = 'bottom-right';
00041 const POSITION_STRETCH = 'stretch';
00042 const POSITION_TILE = 'tile';
00043
00044 protected $_fileType = null;
00045 protected $_fileName = null;
00046 protected $_fileMimeType = null;
00047 protected $_fileSrcName = null;
00048 protected $_fileSrcPath = null;
00049 protected $_imageHandler = null;
00050 protected $_imageSrcWidth = null;
00051 protected $_imageSrcHeight = null;
00052 protected $_requiredExtensions = null;
00053 protected $_watermarkPosition = null;
00054 protected $_watermarkWidth = null;
00055 protected $_watermarkHeigth = null;
00056
00057 protected $_keepAspectRatio;
00058 protected $_keepFrame;
00059 protected $_keepTransparency;
00060 protected $_backgroundColor;
00061 protected $_constrainOnly;
00062
00063 abstract public function open($fileName);
00064
00065 abstract public function save($destination=null, $newName=null);
00066
00067 abstract public function display();
00068
00069 abstract public function resize($width=null, $height=null);
00070
00071 abstract public function rotate($angle);
00072
00073 abstract public function crop($top=0, $left=0, $right=0, $bottom=0);
00074
00075 abstract public function watermark($watermarkImage, $positionX=0, $positionY=0, $watermarkImageOpacity=30, $repeat=false);
00076
00077 abstract public function checkDependencies();
00078
00079 public function getMimeType()
00080 {
00081 if( $this->_fileType ) {
00082 return $this->_fileType;
00083 } else {
00084 list($this->_imageSrcWidth, $this->_imageSrcHeight, $this->_fileType, ) = getimagesize($this->_fileName);
00085 $this->_fileMimeType = image_type_to_mime_type($this->_fileType);
00086 return $this->_fileMimeType;
00087 }
00088 }
00089
00090
00091
00092
00093
00094
00095 public function getOriginalWidth()
00096 {
00097 $this->getMimeType();
00098 return $this->_imageSrcWidth;
00099 }
00100
00101
00102
00103
00104
00105
00106 public function getOriginalHeight()
00107 {
00108 $this->getMimeType();
00109 return $this->_imageSrcHeight;
00110 }
00111
00112 public function setWatermarkPosition($position)
00113 {
00114 $this->_watermarkPosition = $position;
00115 return $this;
00116 }
00117
00118 public function getWatermarkPosition()
00119 {
00120 return $this->_watermarkPosition;
00121 }
00122
00123 public function setWatermarkWidth($width)
00124 {
00125 $this->_watermarkWidth = $width;
00126 return $this;
00127 }
00128
00129 public function getWatermarkWidth()
00130 {
00131 return $this->_watermarkWidth;
00132 }
00133
00134 public function setWatermarkHeigth($heigth)
00135 {
00136 $this->_watermarkHeigth = $heigth;
00137 return $this;
00138 }
00139
00140 public function getWatermarkHeigth()
00141 {
00142 return $this->_watermarkHeigth;
00143 }
00144
00145
00146
00147
00148
00149
00150
00151
00152 public function keepAspectRatio($value = null)
00153 {
00154 if (null !== $value) {
00155 $this->_keepAspectRatio = (bool)$value;
00156 }
00157 return $this->_keepAspectRatio;
00158 }
00159
00160
00161
00162
00163
00164
00165
00166 public function keepFrame($value = null)
00167 {
00168 if (null !== $value) {
00169 $this->_keepFrame = (bool)$value;
00170 }
00171 return $this->_keepFrame;
00172 }
00173
00174
00175
00176
00177
00178
00179
00180 public function keepTransparency($value = null)
00181 {
00182 if (null !== $value) {
00183 $this->_keepTransparency = (bool)$value;
00184 }
00185 return $this->_keepTransparency;
00186 }
00187
00188
00189
00190
00191
00192
00193
00194 public function constrainOnly($value = null)
00195 {
00196 if (null !== $value) {
00197 $this->_constrainOnly = (bool)$value;
00198 }
00199 return $this->_constrainOnly;
00200 }
00201
00202
00203
00204
00205
00206
00207
00208 public function backgroundColor($value = null)
00209 {
00210 if (null !== $value) {
00211 if ((!is_array($value)) || (3 !== count($value))) {
00212 return;
00213 }
00214 foreach ($value as $color) {
00215 if ((!is_integer($color)) || ($color < 0) || ($color > 255)) {
00216 return;
00217 }
00218 }
00219 }
00220 $this->_backgroundColor = $value;
00221 return $this->_backgroundColor;
00222 }
00223
00224 protected function _getFileAttributes()
00225 {
00226 $pathinfo = pathinfo($this->_fileName);
00227
00228 $this->_fileSrcPath = $pathinfo['dirname'];
00229 $this->_fileSrcName = $pathinfo['basename'];
00230 }
00231 }