用C實現PHP擴充 Image_Tool 圖片常用處理工具類的使用

來源:互聯網
上載者:User
一、類文檔說明

class Image_Tool{    /**     * 構造Image_Tool對象     * @param string|array $img_data     * $img_data可以為圖片的路徑     */ function __construct($img_data=""); /**  * 添加文字註解,或用於文字浮水印  * @access public  * @param string $txt UTF8編碼的文本  * @param float $opacity 設定透明度  * @param constant $gravity   * 設定文字擺放位置:  * NorthWest,North,NorthEast,West, Center,East,SouthWest,South,SouthEast,Static  * @param array $font 字型數組可以設定如下屬性:  * name,常量,字型名稱,如果需要添加中文註解,請使用中文字型,否則中文會顯示亂碼。     *        支援的字型:SimSun(宋體,預設)、SimKai(楷體)、SimHei(正黑)、MicroHei(微米黑)、Arial     * weight,字型寬度,int     * size,字型大小,int     * color,字型顏色,例如:"blue", "#0000ff", "rgb(0,0,255)"等,預設為"black";     * @return boolean  */ function annotate($txt, $opacity, $gravity, array $font); /**  * 將對象的資料重新初始化,用於多次重用一個Image_Tool對象  * @access public  * @return void  */ function clean(); *  * 圖片合成,可以進行多張圖片的合成,也可以做圖片浮水印用  * @access public  * @param int $src_img 合成的靶心圖表片,可以為ImageTool對象或圖片位元據  * @param int $x 合成在畫布的X座標  * @param string $y 合成在畫布的Y座標  * @return boolean  *  function composite($src_img, $x, $y); /**  * 返回錯誤資訊  * @access public  * @return string  */ function errmsg(); /**  * 返回錯誤編號  * @access public  * @return int  */ function errcode(); /**  * 進行圖片處理操作  * @access public  * @param string $format  * @param boolean $display  * @return boolean|string 若設定$display為true,返回void,否則返回圖片位元據。失敗時返回false  */ function exec($format, $display=false); /**  * 水平翻轉  * @access public  * @return boolean  */ function flipH(); /**  * 垂直翻轉  * @access public  * @return boolean  */ function flipV(); /**  * 取得圖片屬性  * @access public  * @return array|boolean 錯誤返回false  */ function getImageAttr(); /**  * 去噪點,改善圖片品質,通常用於exec之前  * @access public  * @return boolean  */ function improve(); /**  * 縮放圖片,只指定width或者height時,將進行等比縮放  * @access public  * @param int $width  * @param int $height  * @param boolean $thumbnail 是否清除圖片附加資訊  * @return boolean  */ function resize($width, $height, $thumbnail=true); /**  * 按比例縮放.1為原大小  * @access public  * @param float $ratio  * @param boolean $thumbnail 是否清除圖片附加資訊  * @return boolean  */ function resizeRatio($ratio, $thumbnail=true); /**  * 順時針旋轉圖片  * @access public  * @param int $degree 旋轉度數(0 - 360)  * @return boolean  */ function rotate($degree=90); /**  * 設定要處理的圖片位元據  * @access public  * @param string $img_blob  * @return boolean  */ function setData($img_blob);}

三、擴充實現
1.php_fetch_url.h

/*  +----------------------------------------------------------------------+  | PHP Version 5                                                        |  +----------------------------------------------------------------------+  | Copyright (c) 1997-2012 The PHP Group                                |  +----------------------------------------------------------------------+  | This source file is subject to version 3.01 of the PHP license,      |  | that is bundled with this package in the file LICENSE, and is        |  | available through the world-wide-web at the following url:           |  | http://www.php.net/license/3_01.txt                                  |  | If you did not receive a copy of the PHP license and are unable to   |  | obtain it through the world-wide-web, please send a note to          |  | license@php.net so we can mail you a copy immediately.               |  +----------------------------------------------------------------------+  | Author:                                                              |  +----------------------------------------------------------------------+*//* $Id$ */#ifndef PHP_IMAGE_TOOL_H#define PHP_IMAGE_TOOL_Hextern zend_module_entry image_tool_module_entry;#define phpext_image_tool_ptr &image_tool_module_entry#ifdef PHP_WIN32# define PHP_IMAGE_TOOL_API __declspec(dllexport)#elif defined(__GNUC__) && __GNUC__ >= 4# define PHP_IMAGE_TOOL_API __attribute__ ((visibility("default")))#else# define PHP_IMAGE_TOOL_API#endif#ifdef ZTS#include "TSRM.h"#endif#define FETCH_THIS Z_OBJCE_P(getThis()), getThis()#define IMAGETOOL_MAGICKWAND_RSRC_NAME "MagickWand"#define IMAGETOOL_PIXELWAND_RSRC_NAME "PixelWand"#define IMAGETOOL_NORTHWEST 1#define IMAGETOOL_NORTH     2#define IMAGETOOL_NORTHEAST 3#define IMAGETOOL_WEST      4#define IMAGETOOL_CENTER    5#define IMAGETOOL_EAST      6#define IMAGETOOL_SOUTHWEST 7#define IMAGETOOL_SOUTH     8#define IMAGETOOL_SOUTHEAST 9#define IMAGETOOL_STATIC    10#define IMAGETOOL_TOP_LEFT      1#define IMAGETOOL_TOP_CENTER    2#define IMAGETOOL_TOP_RIGHT     3#define IMAGETOOL_CENTER_LEFT   4#define IMAGETOOL_CENTER_CENTER 5#define IMAGETOOL_CENTER_RIGHT  6#define IMAGETOOL_BOTTOM_LEFT   7#define IMAGETOOL_BOTTOM_CENTER 8#define IMAGETOOL_BOTTOM_RIGHT  9#define GET_MAGICK_WAND(zval, magick_wand) zval = zend_read_property(FETCH_THIS, ZEND_STRL("magick_wand"), 0 TSRMLS_CC);\        ZEND_FETCH_RESOURCE_NO_RETURN(magick_wand, MagickWand*, &zval, -1, IMAGETOOL_MAGICKWAND_RSRC_NAME, le_image_wand);PHP_MINIT_FUNCTION(image_tool);PHP_MSHUTDOWN_FUNCTION(image_tool);PHP_RINIT_FUNCTION(image_tool);PHP_RSHUTDOWN_FUNCTION(image_tool);PHP_MINFO_FUNCTION(image_tool);#ifdef ZTS#define IMAGE_TOOL_G(v) TSRMG(image_tool_globals_id, zend_image_tool_globals *, v)#else#define IMAGE_TOOL_G(v) (image_tool_globals.v)#endif#endif /* PHP_IMAGE_TOOL_H */

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.