Mage_Media_Model_Image Class Reference

Inheritance diagram for Mage_Media_Model_Image:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 setConfig (Mage_Media_Model_Image_Config_Interface $config)
 getConfig ()
 getImage ()
 getTmpImage ()
 getDimensions ()
 getDestanationDimensions ()
 getExtension ()
 getFilePath ($useParams=false)
 getFileUrl ($useParams=false)
 getName ()
 addParam ($param, $value=null)
 setParam ($param, $value=null)
 getParam ($param)
 getParams ()
 getParamsSum ()
 getSpecialLink ($file, $size, $extension=null, $watermark=null)
 hasSpecialImage ()

Protected Member Functions

 _construct ()
 _removeResources ()

Protected Attributes

 $_config
 $_image
 $_tmpImage
 $_params = array()


Detailed Description

Definition at line 35 of file Image.php.


Member Function Documentation

_construct (  )  [protected]

Enter description here...

Reimplemented from Varien_Object.

Definition at line 66 of file Image.php.

00067     {
00068         $this->_init('media/image');
00069     }

_removeResources (  )  [protected]

Definition at line 269 of file Image.php.

00270     {
00271         if ($this->_image) {
00272             $this->_getResource()->destroyResource($this->_image);
00273             $this->_image = null;
00274         }
00275 
00276         if ($this->_tmpImage) {
00277             $this->_getResource()->destroyResource($this->_tmpImage);
00278             $this->_tmpImage = null;
00279         }
00280     }

addParam ( param,
value = null 
)

Definition at line 172 of file Image.php.

00173     {
00174         if(is_array($param)) {
00175             $this->_params = array_merge($this->_params, $param);
00176         } else {
00177             $this->_params[$param] = $value;
00178         }
00179 
00180         return $this;
00181     }

getConfig (  ) 

Retrive media image config instance

Returns:
Mage_Media_Model_Image_Config_Interface

Definition at line 88 of file Image.php.

00089     {
00090         return $this->_config;
00091     }

getDestanationDimensions (  ) 

Retrive destanation dimensions object

Returns:
Varien_Object

Definition at line 129 of file Image.php.

00130     {
00131         if(!$this->getData('destanation_dimensions')) {
00132             $this->setData('destanation_dimensions', clone $this->getDimensions());
00133         }
00134 
00135         return $this->getData('destanation_dimensions');
00136     }

getDimensions (  ) 

Retrive source dimensions object

Returns:
Varien_Object

Definition at line 116 of file Image.php.

00117     {
00118         if(!$this->getData('dimensions')) {
00119             $this->setData('dimensions', $this->_getResource()->getDimensions($this));
00120         }
00121         return $this->getData('dimensions');
00122     }

getExtension (  ) 

Definition at line 138 of file Image.php.

00139     {
00140         return substr($this->getFileName(), strrpos($this->getFileName(), '.')+1);
00141     }

getFilePath ( useParams = false  ) 

Definition at line 143 of file Image.php.

00144     {
00145         if($useParams && sizeof($this->getParams())) {
00146             $changes = '.' . $this->getParamsSum();
00147         } else {
00148             $changes = '';
00149         }
00150 
00151         return $this->getConfig()->getBaseMediaPath() . DS . $this->getName() . $changes . '.'
00152              . ( ( $useParams && $this->getParam('extension')) ? $this->getParam('extension') : $this->getExtension() );
00153     }

getFileUrl ( useParams = false  ) 

Definition at line 155 of file Image.php.

00156     {
00157         if($useParams && sizeof($this->getParams())) {
00158             $changes = '.' . $this->getParamsSum();
00159         } else {
00160             $changes = '';
00161         }
00162 
00163         return $this->getConfig()->getBaseMediaUrl() . '/' . $this->getName() . $changes . '.'
00164              . ( ( $useParams && $this->getParam('extension')) ? $this->getParam('extension') : $this->getExtension() );
00165     }

getImage (  ) 

Definition at line 93 of file Image.php.

00094     {
00095         if(is_null($this->_image)) {
00096             $this->_image = $this->_getResource()->getImage($this);
00097         }
00098 
00099         return $this->_image;
00100     }

getName (  ) 

Definition at line 167 of file Image.php.

00168     {
00169         return substr($this->getFileName(), 0, strrpos($this->getFileName(), '.'));
00170     }

getParam ( param  ) 

Definition at line 194 of file Image.php.

00195     {
00196         if(isset($this->_params[$param])) {
00197             return $this->_params[$param];
00198         }
00199 
00200         return null;
00201     }

getParams (  ) 

Definition at line 203 of file Image.php.

00204     {
00205         return $this->_params;
00206     }

getParamsSum (  ) 

Definition at line 208 of file Image.php.

00209     {
00210         return md5(serialize($this->_params));
00211     }

getSpecialLink ( file,
size,
extension = null,
watermark = null 
)

Return special link (with creating image if not exists)

Parameters:
string $file
string $size
string $extension
string $watermark
Returns:
string

Definition at line 222 of file Image.php.

00223     {
00224         $this->_removeResources();
00225         $this->setData(array());
00226         $this->setParam(array());
00227         $this->setFileName($file);
00228 
00229         $this->addParam('size', $size);
00230         $this->addParam('watermark', $watermark);
00231         $this->addParam('extension', $extension);
00232 
00233         if(!$this->hasSpecialImage()) {
00234             if (strpos($size, 'x')!==false) {
00235                list($width, $height) = explode('x', $size);
00236             } else {
00237                 $width = $size;
00238                 $height = $this->getDimensions()->getHeight();
00239             }
00240 
00241             $sizeHRate = $width / $this->getDimensions()->getWidth();
00242             $sizeVRate = $height / $this->getDimensions()->getHeight();
00243 
00244             $rate = min($sizeHRate, $sizeVRate);
00245 
00246             if ($rate > 1) { // If image smaller than needed
00247                 $rate = 1;
00248             }
00249 
00250             $this->getDestanationDimensions()
00251                 ->setWidth($rate*$this->getDimensions()->getWidth())
00252                 ->setHeight($rate*$this->getDimensions()->getHeight());
00253 
00254 
00255             $this->_getResource()->resize($this);
00256             $this->_getResource()->watermark($this);
00257             $this->_getResource()->saveAs($this, $extension);
00258             $this->_removeResources();
00259         }
00260 
00261         return $this->getFileUrl(true);
00262     }

getTmpImage (  ) 

Definition at line 102 of file Image.php.

00103     {
00104         if(is_null($this->_image)) {
00105             $this->_tmpImage = $this->_getResource()->getTmpImage($this);
00106         }
00107 
00108         return $this->_tmpImage;
00109     }

hasSpecialImage (  ) 

Definition at line 264 of file Image.php.

00265     {
00266         return $this->_getResource()->hasSpecialImage($this);
00267     }

setConfig ( Mage_Media_Model_Image_Config_Interface config  ) 

Set media image config instance

Parameters:
Mage_Media_Model_Image_Config_Interface $config
Returns:
unknown

Definition at line 77 of file Image.php.

00078     {
00079         $this->_config = $config;
00080         return $this;
00081     }

setParam ( param,
value = null 
)

Definition at line 183 of file Image.php.

00184     {
00185         if(is_array($param)) {
00186             $this->_params = $param;
00187         } else {
00188             $this->_params[$param] = $value;
00189         }
00190 
00191         return $this;
00192     }


Member Data Documentation

$_config [protected]

Definition at line 42 of file Image.php.

$_image [protected]

Definition at line 49 of file Image.php.

$_params = array() [protected]

Definition at line 63 of file Image.php.

$_tmpImage [protected]

Definition at line 56 of file Image.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:29 2009 for Magento by  doxygen 1.5.8