Example #1
0
 /**
  * addText
  *
  * @param   array   options     Array contains options
  *                              array(
  *                                  'text'  The string to draw
  *                                  'x'     Horizontal position
  *                                  'y'     Vertical Position
  *                                  'Color' Font color
  *                                  'font'  Font to be used
  *                                  'size'  Size of the fonts in pixel
  *                                  'resize_first'  Tell if the image has to be resized
  *                                                  before drawing the text
  *                              )
  *
  * @return bool|PEAR_Error TRUE or a PEAR_Error object on error
  * @access public
  */
 function addText($params)
 {
     static $default_params = array('text' => 'This is a Text', 'x' => 10, 'y' => 20, 'size' => 12, 'color' => 'red', 'font' => 'Helvetica', 'resize_first' => false);
     $params = array_merge($default_params, $params);
     $params['color'] = is_array($params['color']) ? $this->colorarray2colorhex($params['color']) : strtolower($params['color']);
     static $cmds = array('setfillcolor' => 'color', 'setfontsize' => 'size', 'setfontface' => 'font');
     imagick_begindraw($this->imageHandle);
     foreach ($cmds as $cmd => $v) {
         if (!call_user_func('imagick_' . $cmd, $this->imageHandle, $parms[$v])) {
             return $this->raiseError("Problem with adding Text::{$v} = {$parms[$v]}", IMAGE_TRANSFORM_ERROR_FAILED);
         }
     }
     if (!imagick_drawannotation($this->imageHandle, $params['x'], $params['y'], $params['text'])) {
         return $this->raiseError('Problem with adding Text', IMAGE_TRANSFORM_ERROR_FAILED);
     }
     return true;
 }
Example #2
0
 /**
  * addText
  *
  * @param   array   options     Array contains options
  *                              array(
  *                                  'text'  The string to draw
  *                                  'x'     Horizontal position
  *                                  'y'     Vertical Position
  *                                  'Color' Font color
  *                                  'font'  Font to be used
  *                                  'size'  Size of the fonts in pixel
  *                                  'resize_first'  Tell if the image has to be resized
  *                                                  before drawing the text
  *                              )
  *
  * @return bool|PEAR_Error TRUE or a PEAR_Error object on error
  * @access public
  */
 public function addText($params)
 {
     $this->oldImage = $this->imageHandle;
     $params = array_merge($this->_get_default_text_params(), $params);
     if (is_array($params['color'])) {
         $params['color'] = $this->colorarray2colorhex($params['color']);
     } else {
         $params['color'] = strtolower($params['color']);
     }
     static $cmds = array('setfillcolor' => 'color', 'setfontsize' => 'size', 'setfontface' => 'font');
     imagick_begindraw($this->imageHandle);
     foreach ($cmds as $cmd => $v) {
         if (!call_user_func('imagick_' . $cmd, $this->imageHandle, $params[$v])) {
             return $this->raiseError("Problem with adding Text::{$v} = {$params[$v]}", IMAGE_TRANSFORM_ERROR_FAILED);
         }
     }
     if (!imagick_drawannotation($this->imageHandle, $params['x'], $params['y'], $params['text'])) {
         return $this->raiseError('Problem with adding Text', IMAGE_TRANSFORM_ERROR_FAILED);
     }
     return true;
 }