Mage_Media_Model_File_Image Class Reference

Inheritance diagram for Mage_Media_Model_File_Image:

Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 load (Mage_Media_Model_Image $object, $file, $field=null)
 save (Mage_Media_Model_Image $object)
 delete (Mage_Media_Model_Image $object)
 getImage (Mage_Media_Model_Image $object)
 getTmpImage (Mage_Media_Model_Image $object)
 resize (Mage_Media_Model_Image $object)
 watermark (Mage_Media_Model_Image $object)
 saveAs (Mage_Media_Model_Image $object, $extension=null)
 getDimensions (Mage_Media_Model_Image $object)
 destroyResource (&$resource)
 hasSpecialImage (Mage_Media_Model_Image $object)

Protected Member Functions

 _construct ()
 _getReadAdapter ()
 _getWriteAdapter ()


Detailed Description

Definition at line 35 of file Image.php.


Member Function Documentation

_construct (  )  [protected]

Resource initialization

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 40 of file Image.php.

00041     {
00042         return $this;
00043     }

_getReadAdapter (  )  [protected]

Retrieve connection for read data

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 48 of file Image.php.

00049     {
00050         return false;
00051     }

_getWriteAdapter (  )  [protected]

Retrieve connection for write data

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 56 of file Image.php.

00057     {
00058         return false;
00059     }

delete ( Mage_Media_Model_Image object  ) 

Definition at line 73 of file Image.php.

00074     {
00075         return $this;
00076     }

destroyResource ( &$  resource  ) 

Destroys resource object

Parameters:
resource $resource

Definition at line 213 of file Image.php.

00214     {
00215         imagedestroy($resource);
00216         return $this;
00217     }

getDimensions ( Mage_Media_Model_Image object  ) 

Retrive image dimensions

Parameters:
Mage_Media_Model_Image $object
Returns:
Varien_Object

Definition at line 197 of file Image.php.

00198     {
00199         $info = @getimagesize($object->getFilePath());
00200         if(!$info) {
00201             Mage::throwException(Mage::helper('media')->__('Image not exists or invalid'));
00202         }
00203 
00204         $info = array('width'=>$info[0], 'height'=>$info[1], 'type'=>$info[2]);
00205         return new Varien_Object($info);
00206     }

getImage ( Mage_Media_Model_Image object  ) 

Create image resource for operation from file

Parameters:
Mage_Media_Model_Image $object
Returns:
Mage_Media_Model_File_Image

Definition at line 84 of file Image.php.

00085     {
00086         $resource = false;
00087         switch(strtolower($object->getExtension())) {
00088             case 'jpg':
00089             case 'jpeg':
00090                 $resource = imagecreatefromjpeg($object->getFilePath());
00091                 break;
00092 
00093             case 'gif':
00094                 $resource = imagecreatefromgif($object->getFilePath());
00095                 break;
00096 
00097             case 'png':
00098                 $resource = imagecreatefrompng($object->getFilePath());
00099                 break;
00100         }
00101 
00102         if(!$resource) {
00103             Mage::throwException(Mage::helper('media')->__('Image not exists or invalid'));
00104         }
00105 
00106 
00107         return $resource;
00108     }

getTmpImage ( Mage_Media_Model_Image object  ) 

Create tmp image resource for operations

Parameters:
Mage_Media_Model_Image $object
Returns:
Mage_Media_Model_File_Image

Definition at line 116 of file Image.php.

00117     {
00118         $resource = imagecreatetruecolor($object->getDestanationDimensions()->getWidth(), $object->getDestanationDimensions()->getHeight());
00119         return $resource;
00120     }

hasSpecialImage ( Mage_Media_Model_Image object  ) 

Destroys resource object

Parameters:
resource $resource

Definition at line 224 of file Image.php.

00225     {
00226         if(file_exists($object->getFilePath(true))) {
00227             return true;
00228         }
00229 
00230         return false;
00231     }

load ( Mage_Media_Model_Image object,
file,
field = null 
)

Definition at line 61 of file Image.php.

00062     {
00063         // Do some implementation
00064         return $this;
00065     }

resize ( Mage_Media_Model_Image object  ) 

Resize image

Parameters:
Mage_Media_Model_Image $object
Returns:
Mage_Media_Model_File_Image

Definition at line 128 of file Image.php.

00129     {
00130         $tmpImage = $object->getTmpImage();
00131         $sourceImage = $object->getImage();
00132 
00133         imagecopyresampled(
00134             $tmpImage,
00135             $sourceImage,
00136             0, 0, 0, 0,
00137             $object->getDestanationDimensions()->getWidth(),
00138             $object->getDestanationDimensions()->getHeight(),
00139             $object->getDimensions()->getWidth(),
00140             $object->getDimensions()->getHeight()
00141         );
00142 
00143         return $this;
00144     }

save ( Mage_Media_Model_Image object  ) 

Definition at line 67 of file Image.php.

00068     {
00069         // Do some implementation
00070         return $this;
00071     }

saveAs ( Mage_Media_Model_Image object,
extension = null 
)

Creates image

Parameters:
Mage_Media_Model_Image $object
string|null $extension
Returns:
Mage_Media_Model_File_Image

Definition at line 164 of file Image.php.

00165     {
00166         if(is_null($extension)) {
00167             $extension = $object->getExtension();
00168         }
00169 
00170         $result = false;
00171         switch (strtolower($extension)) {
00172             case 'jpg':
00173             case 'jpeg':
00174                 $result = imagejpeg($object->getTmpImage(), $object->getFilePath(true), 80);
00175                 break;
00176             case 'gif':
00177                 $result = imagegif($object->getTmpImage(), $object->getFilePath(true));
00178                 break;
00179             case 'png':
00180                 $result = imagepng($object->getTmpImage(), $object->getFilePath(true));
00181                 break;
00182         }
00183 
00184         if(!$result) {
00185             Mage::throwException(Mage::helper('media')->__('Error while creating image'));
00186         }
00187 
00188         return $this;
00189     }

watermark ( Mage_Media_Model_Image object  ) 

Add watermark for image

Parameters:
Mage_Media_Model_Image $object
Returns:
Mage_Media_Model_File_Image

Definition at line 152 of file Image.php.

00153     {
00154         return $this;
00155     }


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