/** * 旋转 * @param int $degree 要旋转的角度 * @return bool 成功返回true,失败返回false */ public function rotate($degree) { return MagickRotateImage(self::$resource, 'white', $degree); }
/** * liberty_magickwand_rotate_image * * @param array $pFileHash * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ function liberty_magickwand_rotate_image(&$pFileHash) { $ret = FALSE; $magickWand = NewMagickWand(); $pFileHash['error'] = NULL; if (!empty($pFileHash['source_file']) && is_file($pFileHash['source_file'])) { if ($error = liberty_magickwand_check_error(MagickReadImage($magickWand, $pFileHash['source_file']), $magickWand)) { $pFileHash['error'] = $error; } elseif (empty($pFileHash['degrees']) || !is_numeric($pFileHash['degrees'])) { $pFileHash['error'] = tra('Invalid rotation amount'); } else { $bgWand = NewPixelWand('white'); if ($error = liberty_magickwand_check_error(MagickRotateImage($magickWand, $bgWand, $pFileHash['degrees']), $magickWand)) { $pFileHash['error'] .= $error; } if ($error = liberty_magickwand_check_error(MagickWriteImage($magickWand, $pFileHash['source_file']), $magickWand)) { $pFileHash['error'] .= $error; } } } else { $pFileHash['error'] = "No source file to resize"; } return empty($pFileHash['error']); }
/** * Rotate the image clockwise * * @param Asido_TMP &$tmp * @param float $angle * @param Asido_Color &$color * @return boolean * @access protected */ function __rotate(&$tmp, $angle, &$color) { // skip full loops // if ($angle % 360 == 0) { return true; } list($r, $g, $b) = $color->get(); $ret = MagickRotateImage($tmp->target, NewPixelWand("rgb({$r},{$g},{$b})"), $angle); $tmp->image_width = MagickGetImageWidth($tmp->target); $tmp->image_height = MagickGetImageHeight($tmp->target); return $ret; }
/** * 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; }