Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class MagentoGarden_Image
- {
- private $_adapter = null;
- private $_fileName = null;
- /**
- * Constructor
- *
- * @param Varien_Image_Adapter $adapter. Default value is GD2
- * @param string $fileName
- * @return void
- */
- function __construct($fileName = null, $adapter = MagentoGarden_Image_Adapter::ADAPTER_GD2)
- {
- $this->_getAdapter($adapter);
- $this->_fileName = $fileName;
- if (isset($fileName)) {
- $this->open();
- }
- }
- /**
- * Opens an image and creates image handle
- *
- * @access public
- * @return void
- */
- function open()
- {
- $this->_getAdapter()->checkDependencies();
- if (!file_exists($this->_fileName)) {
- throw new Exception('' . 'File \'' . $this->_fileName . '\' does not exists.');
- }
- $this->_getAdapter()->open($this->_fileName);
- }
- /**
- * Display handled image in your browser
- *
- * @access public
- * @return void
- */
- function display()
- {
- $this->_getAdapter()->display();
- }
- /**
- * Save handled image into file
- *
- * @param string $destination. Default value is NULL
- * @param string $newFileName. Default value is NULL
- * @access public
- * @return void
- */
- function save($destination = null, $newFileName = null)
- {
- $this->_getAdapter()->save($destination, $newFileName);
- }
- /**
- * Rotate an image.
- *
- * @param int $angle
- * @access public
- * @return void
- */
- function rotate($angle)
- {
- $this->_getAdapter()->rotate($angle);
- }
- /**
- * Crop an image.
- *
- * @param int $top. Default value is 0
- * @param int $left. Default value is 0
- * @param int $right. Default value is 0
- * @param int $bottom. Default value is 0
- * @access public
- * @return void
- */
- function crop($top = 0, $left = 0, $right = 0, $bottom = 0)
- {
- $this->_getAdapter()->crop($top, $left, $right, $bottom);
- }
- /**
- * Resize an image
- *
- * @param int $width
- * @param int $height
- * @access public
- * @return void
- */
- function resize($width, $height = null)
- {
- $this->_getAdapter()->resize($width, $height);
- }
- function keepAspectRatio($value)
- {
- return $this->_getAdapter()->keepAspectRatio($value);
- }
- function keepFrame($value)
- {
- return $this->_getAdapter()->keepFrame($value);
- }
- function keepTransparency($value)
- {
- return $this->_getAdapter()->keepTransparency($value);
- }
- function constrainOnly($value)
- {
- return $this->_getAdapter()->constrainOnly($value);
- }
- function backgroundColor($value)
- {
- return $this->_getAdapter()->backgroundColor($value);
- }
- /**
- * Get/set quality, values in percentage from 0 to 100
- *
- * @param int $value
- * @return int
- */
- function quality($value)
- {
- return $this->_getAdapter()->quality($value);
- }
- /**
- * Adds watermark to our image.
- *
- * @param string $watermarkImage. Absolute path to watermark image.
- * @param int $positionX. Watermark X position.
- * @param int $positionY. Watermark Y position.
- * @param int $watermarkImageOpacity. Watermark image opacity.
- * @param bool $repeat. Enable or disable watermark brick.
- * @access public
- * @return void
- */
- function watermark($watermarkImage, $positionX = 0, $positionY = 0, $watermarkImageOpacity = 30, $repeat = false)
- {
- if (!file_exists($watermarkImage)) {
- throw new Exception('' . 'Required file \'' . $watermarkImage . '\' does not exists.');
- }
- $this->_getAdapter()->watermark($watermarkImage, $positionX, $positionY, $watermarkImageOpacity, $repeat);
- }
- /**
- * Get mime type of handled image
- *
- * @access public
- * @return string
- */
- function getMimeType()
- {
- return $this->_getAdapter()->getMimeType();
- }
- /**
- * process
- *
- * @access public
- * @return void
- */
- function process()
- {
- }
- /**
- * instruction
- *
- * @access public
- * @return void
- */
- function instruction()
- {
- }
- /**
- * Set image background color
- *
- * @param int $color
- * @access public
- * @return void
- */
- function setImageBackgroundColor($color)
- {
- $this->_getAdapter()->imageBackgroundColor = intval($color);
- }
- function setIsCategoryWatermark($_value)
- {
- $this->_getAdapter()->setIsCategoryWatermark($_value);
- return $this;
- }
- function setPositionType($_position_type)
- {
- $this->_getAdapter()->setPositionType($_position_type);
- return $this;
- }
- /**
- * Set watermark position
- *
- * @param string $position
- * @return Varien_Image
- */
- function setWatermarkPosition($position)
- {
- $this->_getAdapter()->setWatermarkPosition($position);
- return $this;
- }
- /**
- * Set watermark image opacity
- *
- * @param int $imageOpacity
- * @return Varien_Image
- */
- function setWatermarkImageOpacity($imageOpacity)
- {
- $this->_getAdapter()->setWatermarkImageOpacity($imageOpacity);
- return $this;
- }
- /**
- * Set watermark width
- *
- * @param int $width
- * @return Varien_Image
- */
- function setWatermarkWidth($width)
- {
- $this->_getAdapter()->setWatermarkWidth($width);
- return $this;
- }
- /**
- * Set watermark heigth
- *
- * @param int $heigth
- * @return Varien_Image
- */
- function setWatermarkHeigth($heigth)
- {
- $this->_getAdapter()->setWatermarkHeigth($heigth);
- return $this;
- }
- /**
- * Retrieve image adapter object
- *
- * @param string $adapter
- * @return Varien_Image_Adapter_Abstract
- */
- function _getAdapter($adapter = null)
- {
- if (!isset($this->_adapter)) {
- $this->_adapter = MagentoGarden_Image_Adapter::factory($adapter);
- }
- return $this->_adapter;
- }
- /**
- * Retrieve original image width
- *
- * @return int|null
- */
- function getOriginalWidth()
- {
- return $this->_getAdapter()->getOriginalWidth();
- }
- /**
- * Retrieve original image height
- *
- * @return int|null
- */
- function getOriginalHeight()
- {
- return $this->_getAdapter()->getOriginalHeight();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement