public function getImgWand($resource = "", $size = array())
 {
     $result = NewMagickWand();
     if (count($size) == 2) {
         MagickSetWandSize($result, $size[0], $size[1]);
     }
     if (IsMagickWand($resource)) {
         $result = CloneMagickWand($resource);
     } elseif (is_array($resource) && count($resource) == 3) {
         MagickNewImage($result, $resource[1], $resource[2], $resource[0]);
     } elseif (!empty($resource)) {
         MagickReadImage($result, $resource);
     }
     return $result;
 }
Beispiel #2
0
 /**
  * 读取图片
  * @param string $image 图片路径
  */
 public function setImage($image)
 {
     if (is_string($image)) {
         $opts = array('http' => array('timeout' => 5));
         $context = stream_context_create($opts);
         $times = 0;
         do {
             self::$fd = fopen($image, 'r', $include_path = false, $context);
             if (++$times >= 3) {
                 break;
             }
         } while (self::$fd === false);
         MagickReadImageFile(self::$resource, self::$fd);
         self::$resourcek = CloneMagickWand(self::$resource);
     } else {
         if (is_array($image)) {
             MagickNewImage(self::$resource, $image['width'], $image['height'], $image['backgroundColor']);
             MagickSetFormat(self::$resource, $image['format']);
         }
     }
 }
 /**
  * Open the source and target image for processing it
  *
  * @param Asido_TMP &$tmp
  * @return boolean
  * @access protected
  */
 function __open(&$tmp)
 {
     $tmp->source = NewMagickWand();
     $error_open = !MagickReadImage($tmp->source, $tmp->source_filename);
     $error_open &= !($tmp->target = CloneMagickWand($tmp->source));
     // get width & height of the image
     //
     if (!$error_open) {
         $tmp->image_width = MagickGetImageWidth($tmp->source);
         $tmp->image_height = MagickGetImageHeight($tmp->source);
     }
     return !$error_open;
 }