Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (10)

View Page History

{zone-data:proposer-list}
[Dolf Schimmel|mailto:dolfschimmel@gmail.com]
[Marcin Lulek|mailto:ergo14@gmail.com]
[~freak]
[~dcaunt]
{zone-data}

1.1 - 16 Oct 2008: Finished proposal
1.1 - 10 Jan 2009: Ready for community review
1.2 - 28 Jul 2009: Moved to ready for recommendation
{zone-data}

file_put_contents('/path/to/image.png',$image->get()); //
$image->save('/path/to/image.png'); // Both lines do the same
||UC-05||
$options = array('thickness' => 5,
'filled' => true,
'startX' => 10,
'startY' => 15,
'endX' => 50,
'endY' => 125);
$image = new Zend_Image('/path/to/image.png'); // Autodetect adapter to use
$image->drawLine($options);
$image->save();
{zone-data}

{zone-data:skeletons}
Some code (meant to get an impression of the API, not to get an impression of our coding skills) can be found here: http://framework.zend.com/svn/framework/standard/branches/user/freak/ZendImage/

{code}
class Zend_Magic_Exception Zend_Magic_ReadBrain extends Zend_Exception {}

class Zend_Magic {
/** Code is meant as a preliminary example of the API. Actual code may differ **/
class Zend_Image
... {
/**
* Adapter: GD
*/
const ADAPTER_GD = 'Gd';
/**
* Adapter: Imagemick
*/
const ADAPTER_IMAGEMICK = 'Imagemick';

/*
*
* Names of Actions available
*/
const LINE = 'DrawLine';
const POLYGON = 'DrawPolygon';
const ELLIPSE = 'DrawEllipse';
const ARC = 'DrawArc';
const ETC = 'MoreToAddHere';

/**
* Adapter set to use for image operation
*
* @var Zend_Image_Adapter
*/
protected $_adapter = null;

/**
* Path of the location of the image
*/
protected $_imagePath = null;

/**
* Loads the image, if a path is given
*
* @param string $path (Optional) Path to the image
*/
public function __construct ($path = null)
{
if (! is_array($path)) {
$this->setImagePath($path);
}
}

/**
* Sets the adapter to use
* Currently only GD is available
* ImageMagick will follow soon
*
* @param string $adapter (Optional) The adapter to use
* @param boolean $check (Optional) If ture, check if the adapter is available
* @throw Zend_Image_Exception When checked for availability of unavailable adapter
*/
public function setAdapter ($adapter = null, $check = true)
{
if ($adapter) {
$name = 'Zend_Image_Adapter_' . $adapter;
Zend_Loader::loadClass($name);
$this->_adapter = new $name();
} else {
/* No adapter was set. Attempt to detect. */
$check = false;
$this->setAdapter($this->_detectAdapter());
}
if ($check && ! $this->_adapter->isAvailable()) {
require_once 'Zend/Image/Exception.php';
throw new Zend_Image_Exception("Adapter '$adapter' is not available.");
}
$this->setImagePath();
}

/**
* Detects the adapter to use.
* Order: GD, ImageMick
*
* @return Available adapter
*/
protected function _detectAdapter ()
{
if (function_exists('gd_info')) {
return self::ADAPTER_GD;
} elseif(false) {
return self::ADAPTER_IMAGEMICK;
}
return null;
}

/**
* Set the path of the image
*
* @param string $path (Optional) The path of the image
* @throw Zend_Image_Exception if path is set on nonexistent adapter
*/
public function setImagePath ($path = null)
{
if (null !== $path) {
$this->_imagePath = $path;
if (null !== $this->_adapter) {
$this->setImagePath();
}
} else {
if (null === $this->_adapter) {
require_once 'Zend/Image/Exception.php';
throw new Zend_Image_Exception('Cannot set image path on an adapter that hasn\'t been set.');
} elseif (! file_exists($this->_imagePath)) {
require_once 'Zend/Image/Exception.php';
throw new Zend_Image_Exception('Image path does not exist.');
}
$this->_adapter->setPath($this->_imagePath);
}
}

/**
* Perform an action on the image
* @param mixed $param1
* @param array $options Options that will be parsed on to the action
* @return Zend_Image
* @todo: use plugin loader.
*/
public function apply ($param1, $param2 = null)
{
if($param2 instanceof Zend_Image_Action_Abstract ) {
$object = $param2;
} elseif ($param1 instanceof Zend_Image_Action_Abstract) {
$object = $param1;
} else {
$name = 'Zend_Image_Action_' . ucfirst($param1);
Zend_Loader::loadClass($name);
$object = new $name($param2);
}

if (! $this->_adapter) {
$this->setAdapter();
}
$this->_adapter->apply($object);
return $this;
}

public function __call($action,$arguments) {
$this->apply($action,$arguments[0]);
}

/**
* Get a string containing the image
*
* @param string $format (Optional) The format of the image to return
* @return string The actual image
*/
public function render ($format = 'png')
{
return $this->_adapter->getImage($format);
}

public function display($format = 'png',$sendHeader=true) {
if($sendHeader) {
header('Content-type: image/png');
}

echo $this->_adapter->getImage($format);
return true;
}

/**
* Get a string containing the image
*
* @return string The image
*/
public function __toString ()
{
return $this->render();
}
{code}
{zone-data}