Mage_Catalog_Helper_Image Class Reference

Inheritance diagram for Mage_Catalog_Helper_Image:

Mage_Core_Helper_Abstract

List of all members.

Public Member Functions

 init (Mage_Catalog_Model_Product $product, $attributeName, $imageFile=null)
 resize ($width, $height=null)
 keepAspectRatio ($flag)
 keepFrame ($flag, $position=array('center', 'middle'))
 keepTransparency ($flag, $alphaOpacity=null)
 constrainOnly ($flag)
 backgroundColor ($colorRGB)
 rotate ($angle)
 watermark ($fileName, $position, $size=null)
 placeholder ($fileName)
 getPlaceholder ()
 __toString ()
 setWatermarkSize ($size)
 getOriginalWidth ()
 getOriginalHeigh ()
 getOriginalSizeArray ()

Protected Member Functions

 _reset ()
 _setModel ($model)
 _getModel ()
 setAngle ($angle)
 getAngle ()
 setWatermark ($watermark)
 getWatermark ()
 setWatermarkPosition ($position)
 getWatermarkPosition ()
 getWatermarkSize ()
 setProduct ($product)
 getProduct ()
 setImageFile ($file)
 getImageFile ()
 parseSize ($string)

Protected Attributes

 $_model
 $_scheduleResize = false
 $_scheduleWatermark = false
 $_scheduleRotate = false
 $_angle
 $_watermark
 $_watermarkPosition
 $_watermarkSize
 $_product
 $_imageFile
 $_placeholder


Detailed Description

Catalog image helper

Author:
Magento Core Team <core@magentocommerce.com>

Definition at line 32 of file Image.php.


Member Function Documentation

__toString (  ) 

Definition at line 213 of file Image.php.

00214     {
00215         try {
00216             if( $this->getImageFile() ) {
00217                 $this->_getModel()->setBaseFile( $this->getImageFile() );
00218             } else {
00219                 $this->_getModel()->setBaseFile( $this->getProduct()->getData($this->_getModel()->getDestinationSubdir()) );
00220             }
00221 
00222             if( $this->_getModel()->isCached() ) {
00223                 return $this->_getModel()->getUrl();
00224             } else {
00225                 if( $this->_scheduleRotate ) {
00226                     $this->_getModel()->rotate( $this->getAngle() );
00227                 }
00228 
00229                 if ($this->_scheduleResize) {
00230                     $this->_getModel()->resize();
00231                 }
00232 
00233                 if( $this->_scheduleWatermark ) {
00234                     $this->_getModel()
00235                         ->setWatermarkPosition( $this->getWatermarkPosition() )
00236                         ->setWatermarkSize($this->parseSize($this->getWatermarkSize()))
00237                         ->setWatermark($this->getWatermark(), $this->getWatermarkPosition());
00238                 } else {
00239                     if( $watermark = Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_image") ) {
00240                         $this->_getModel()
00241                             ->setWatermarkPosition( $this->getWatermarkPosition() )
00242                             ->setWatermarkSize($this->parseSize($this->getWatermarkSize()))
00243                             ->setWatermark($watermark, $this->getWatermarkPosition());
00244                     }
00245                 }
00246 
00247                 $url = $this->_getModel()->saveFile()->getUrl();
00248             }
00249         } catch( Exception $e ) {
00250             $url = Mage::getDesign()->getSkinUrl($this->getPlaceholder());
00251         }
00252         return $url;
00253     }

_getModel (  )  [protected]

Enter description here...

Returns:
Mage_Catalog_Model_Product_Image

Definition at line 271 of file Image.php.

00272     {
00273         return $this->_model;
00274     }

_reset (  )  [protected]

Reset all previos data

Definition at line 49 of file Image.php.

00050     {
00051         $this->_model = null;
00052         $this->_scheduleResize = false;
00053         $this->_scheduleWatermark = false;
00054         $this->_scheduleRotate = false;
00055         $this->_angle = null;
00056         $this->_watermark = null;
00057         $this->_watermarkPosition = null;
00058         $this->_watermarkSize = null;
00059         $this->_product = null;
00060         $this->_imageFile = null;
00061         return $this;
00062     }

_setModel ( model  )  [protected]

Enter description here...

Returns:
Mage_Catalog_Helper_Image

Definition at line 260 of file Image.php.

00261     {
00262         $this->_model = $model;
00263         return $this;
00264     }

backgroundColor ( colorRGB  ) 

Set color to fill image frame with. Applicable before calling resize() The keepTransparency(true) overrides this (if image has transparent color) It is white by default.

See also:
Mage_Catalog_Model_Product_Image
Parameters:
array $colorRGB
Returns:
Mage_Catalog_Helper_Image

Definition at line 172 of file Image.php.

00173     {
00174         // assume that 3 params were given instead of array
00175         if (!is_array($colorRGB)) {
00176             $colorRGB = func_get_args();
00177         }
00178         $this->_getModel()->setBackgroundColor($colorRGB);
00179         return $this;
00180     }

constrainOnly ( flag  ) 

Guarantee, that image picture will not be bigger, than it was. Applicable before calling resize() It is false by default

Parameters:
bool $flag
Returns:
Mage_Catalog_Helper_Image

Definition at line 156 of file Image.php.

00157     {
00158         $this->_getModel()->setConstrainOnly($flag);
00159         return $this;
00160     }

getAngle (  )  [protected]

Definition at line 282 of file Image.php.

00283     {
00284         return $this->_angle;
00285     }

getImageFile (  )  [protected]

Definition at line 345 of file Image.php.

00346     {
00347         return $this->_imageFile;
00348     }

getOriginalHeigh (  ) 

Retrieve original image height

Returns:
int|null

Definition at line 382 of file Image.php.

00383     {
00384         return $this->_getModel()->getImageProcessor()->getOriginalHeight();
00385     }

getOriginalSizeArray (  ) 

Retrieve Original image size as array 0 - width, 1 - height

Returns:
array

Definition at line 393 of file Image.php.

00394     {
00395         return array(
00396             $this->getOriginalWidth(),
00397             $this->getOriginalHeigh()
00398         );
00399     }

getOriginalWidth (  ) 

Retrieve original image width

Returns:
int|null

Definition at line 372 of file Image.php.

00373     {
00374         return $this->_getModel()->getImageProcessor()->getOriginalWidth();
00375     }

getPlaceholder (  ) 

Definition at line 204 of file Image.php.

00205     {
00206         if (!$this->_placeholder) {
00207             $attr = $this->_getModel()->getDestinationSubdir();
00208             $this->_placeholder = 'images/catalog/product/placeholder/'.$attr.'.jpg';
00209         }
00210         return $this->_placeholder;
00211     }

getProduct (  )  [protected]

Definition at line 334 of file Image.php.

00335     {
00336         return $this->_product;
00337     }

getWatermark (  )  [protected]

Definition at line 293 of file Image.php.

00294     {
00295         return $this->_watermark;
00296     }

getWatermarkPosition (  )  [protected]

Definition at line 304 of file Image.php.

00305     {
00306         if( $this->_watermarkPosition ) {
00307             return $this->_watermarkPosition;
00308         } else {
00309             return Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_position");
00310         }
00311     }

getWatermarkSize (  )  [protected]

Definition at line 319 of file Image.php.

00320     {
00321         if( $this->_watermarkSize ) {
00322             return $this->_watermarkSize;
00323         } else {
00324             return Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_size");
00325         }
00326     }

init ( Mage_Catalog_Model_Product product,
attributeName,
imageFile = null 
)

Definition at line 64 of file Image.php.

00065     {
00066         $this->_reset();
00067         $this->_setModel(Mage::getModel('catalog/product_image'));
00068         $this->_getModel()->setDestinationSubdir($attributeName);
00069         $this->setProduct($product);
00070         if ($imageFile) {
00071             $this->setImageFile($imageFile);
00072         }
00073         else {
00074             // add for work original size
00075             $this->_getModel()->setBaseFile( $this->getProduct()->getData($this->_getModel()->getDestinationSubdir()) );
00076         }
00077         return $this;
00078     }

keepAspectRatio ( flag  ) 

Guarantee, that image picture width/height will not be distorted. Applicable before calling resize() It is true by default.

See also:
Mage_Catalog_Model_Product_Image
Parameters:
bool $flag
Returns:
Mage_Catalog_Helper_Image

Definition at line 106 of file Image.php.

00107     {
00108         $this->_getModel()->setKeepAspectRatio($flag);
00109         return $this;
00110     }

keepFrame ( flag,
position = array('center', 'middle') 
)

Guarantee, that image will have dimensions, set in $width/$height Applicable before calling resize() Not applicable, if keepAspectRatio(false)

$position - TODO, not used for now - picture position inside the frame.

See also:
Mage_Catalog_Model_Product_Image
Parameters:
bool $flag
array $position
Returns:
Mage_Catalog_Helper_Image

Definition at line 124 of file Image.php.

00125     {
00126         $this->_getModel()->setKeepFrame($flag);
00127         return $this;
00128     }

keepTransparency ( flag,
alphaOpacity = null 
)

Guarantee, that image will not lose transparency if any. Applicable before calling resize() It is true by default.

$alphaOpacity - TODO, not used for now

See also:
Mage_Catalog_Model_Product_Image
Parameters:
bool $flag
int $alphaOpacity
Returns:
Mage_Catalog_Helper_Image

Definition at line 142 of file Image.php.

00143     {
00144         $this->_getModel()->setKeepTransparency($flag);
00145         return $this;
00146     }

parseSize ( string  )  [protected]

Enter description here...

Returns:
array

Definition at line 355 of file Image.php.

00356     {
00357         $size = explode('x', strtolower($string));
00358         if( sizeof($size) == 2 ) {
00359             return array(
00360                 'width' => ($size[0] > 0) ? $size[0] : null,
00361                 'heigth' => ($size[1] > 0) ? $size[1] : null,
00362             );
00363         }
00364         return false;
00365     }

placeholder ( fileName  ) 

Definition at line 199 of file Image.php.

00200     {
00201         $this->_placeholder = $fileName;
00202     }

resize ( width,
height = null 
)

Schedule resize of the image $width *or* $height can be null - in this case, lacking dimension will be calculated.

See also:
Mage_Catalog_Model_Product_Image
Parameters:
int $width
int $height
Returns:
Mage_Catalog_Helper_Image

Definition at line 89 of file Image.php.

00090     {
00091         $this->_getModel()->setWidth($width)->setHeight($height);
00092         $this->_scheduleResize = true;
00093         return $this;
00094     }

rotate ( angle  ) 

Definition at line 182 of file Image.php.

00183     {
00184         $this->setAngle($angle);
00185         $this->_getModel()->setAngle($angle);
00186         $this->_scheduleRotate = true;
00187         return $this;
00188     }

setAngle ( angle  )  [protected]

Definition at line 276 of file Image.php.

00277     {
00278         $this->_angle = $angle;
00279         return $this;
00280     }

setImageFile ( file  )  [protected]

Definition at line 339 of file Image.php.

00340     {
00341         $this->_imageFile = $file;
00342         return $this;
00343     }

setProduct ( product  )  [protected]

Definition at line 328 of file Image.php.

00329     {
00330         $this->_product = $product;
00331         return $this;
00332     }

setWatermark ( watermark  )  [protected]

Definition at line 287 of file Image.php.

00288     {
00289         $this->_watermark = $watermark;
00290         return $this;
00291     }

setWatermarkPosition ( position  )  [protected]

Definition at line 298 of file Image.php.

00299     {
00300         $this->_watermarkPosition = $position;
00301         return $this;
00302     }

setWatermarkSize ( size  ) 

Definition at line 313 of file Image.php.

00314     {
00315         $this->_watermarkSize = $size;
00316         return $this;
00317     }

watermark ( fileName,
position,
size = null 
)

Definition at line 190 of file Image.php.

00191     {
00192         $this->setWatermark($fileName)
00193             ->setWatermarkPosition($position)
00194             ->setWatermarkSize($size);
00195         $this->_scheduleWatermark = true;
00196         return $this;
00197     }


Member Data Documentation

$_angle [protected]

Definition at line 38 of file Image.php.

$_imageFile [protected]

Definition at line 43 of file Image.php.

$_model [protected]

Definition at line 34 of file Image.php.

$_placeholder [protected]

Definition at line 44 of file Image.php.

$_product [protected]

Definition at line 42 of file Image.php.

$_scheduleResize = false [protected]

Definition at line 35 of file Image.php.

$_scheduleRotate = false [protected]

Definition at line 37 of file Image.php.

$_scheduleWatermark = false [protected]

Definition at line 36 of file Image.php.

$_watermark [protected]

Definition at line 39 of file Image.php.

$_watermarkPosition [protected]

Definition at line 40 of file Image.php.

$_watermarkSize [protected]

Definition at line 41 of file Image.php.


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

Generated on Sat Jul 4 17:23:37 2009 for Magento by  doxygen 1.5.8