Esempio n. 1
0
 protected function _crop($width, $height, $xoffset = null, $yoffset = null)
 {
     $newWidth = $width == 0 ? $this->getWidth() : $width;
     $newHeight = $height == 0 ? $this->getHeight() : $height;
     $xOffset = $xoffset == 0 ? 0 : $xoffset;
     $yOffset = $yoffset == 0 ? 0 : $yoffset;
     MagickCropImage($this->_resource, $newWidth, $newHeight, $xOffset, $yOffset);
 }
Esempio n. 2
0
 /**
  * 裁剪图片
  * @param int $width  要裁剪的宽度
  * @param int $height 要裁剪的高度
  * @param int $x      裁剪起始横坐标x
  * @param int $y      裁剪起始纵坐标y
  * @return bool       成功返回true,失败返回false
  */
 public function cropImage($width, $height, $x, $y)
 {
     return MagickCropImage(self::$resource, $width, $height, $x, $y);
 }
 /**
  * Crop the image
  *
  * @param Asido_TMP &$tmp
  * @param integer $x
  * @param integer $y
  * @param integer $width
  * @param integer $height
  * @return boolean
  * @access protected
  */
 function __crop(&$tmp, $x, $y, $width, $height)
 {
     if (!MagickCropImage($tmp->target, $width, $height, $x, $y)) {
         return false;
     }
     $t = NewMagickWand();
     MagickNewImage($t, $width, $height);
     if (!MagickCompositeImage($t, $tmp->target, MW_OverCompositeOp, 0, 0)) {
         return false;
     }
     $this->__destroy_target($tmp);
     $tmp->target = $t;
     $tmp->image_width = $width;
     $tmp->image_height = $height;
     return true;
 }
Esempio n. 4
0
 /**
  * Image Process Using MagickWand
  *
  * This function will resize, crop or rotate
  *
  * @access	public
  * @auth	John Meng
  * @param	string
  * @return	bool
  */
 function image_process_magickwand($action = 'resize')
 {
     if (!file_exists($this->full_src_path)) {
         $this->set_error("Image source file not found!");
         return false;
     }
     if (file_exists($this->full_dst_path)) {
         @unlink("{$this->full_dst_path}");
     }
     $magick_wand = NewMagickWand();
     MagickRemoveImageProfiles($magick_wand);
     MagickSetCompressionQuality($magick_wand, $this->quality);
     MagickReadImage($magick_wand, $this->full_src_path);
     switch ($action) {
         case 'crop':
             MagickCropImage($magick_wand, $this->width, $this->height, $this->x_axis, $this->y_axis);
             break;
         case 'rotate':
             switch ($this->rotation_angle) {
                 case 90:
                     $angle = 90;
                     break;
                 case 180:
                     $angle = 180;
                     break;
                 case 270:
                     $angle = 270;
                     break;
                 case 'vrt':
                     $angle = 180;
                     break;
                 case 'hor':
                     $angle = 270;
                     break;
             }
             MagickRotateImage($magick_wand, null, $angle);
             break;
         case 'resize':
         default:
             MagickResizeImage($magick_wand, $this->width, $this->height, MW_LanczosFilter, 1.0);
             break;
     }
     MagickWriteImage($magick_wand, $this->full_dst_path);
     DestroymagickWand($magick_wand);
     // Set the file to 777
     @chmod($this->full_dst_path, $this->dir_write_mode);
     return TRUE;
 }