您好,欢迎访问一九零五行业门户网

用C实现PHP扩展 Image_Tool 图片常用处理工具类的使用

一、类文档说明
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_h extern 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 */
更多用c实现php扩展 image_tool 图片常用处理工具类的使用。
其它类似信息

推荐信息