用C實(shí)現(xiàn)PHP擴(kuò)展 Image_Tool 圖片常用處理工具類(lèi)的使用
一、類(lèi)文檔說(shuō)明
class Image_Tool{
/**
* 構(gòu)造Image_Tool對(duì)象
* @param string|array $img_data
* $img_data可以為圖片的路徑
*/
function __construct($img_data="");
/**
* 添加文字注解,或用于文字水印
* @access public
* @param string $txt UTF8編碼的文本
* @param float $opacity 設(shè)置透明度
* @param constant $gravity
* 設(shè)置文字?jǐn)[放位置:
* NorthWest,North,NorthEast,West, Center,East,SouthWest,South,SouthEast,Static
* @param array $font 字體數(shù)組可以設(shè)置如下屬性:
* name,常量,字體名稱(chēng),如果需要添加中文注解,請(qǐng)使用中文字體,否則中文會(huì)顯示亂碼。
* 支持的字體:SimSun(宋體,默認(rèn))、SimKai(楷體)、SimHei(正黑)、MicroHei(微米黑)、Arial
* weight,字體寬度,int
* size,字體大小,int
* color,字體顏色,例如:"blue", "#0000ff", "rgb(0,0,255)"等,默認(rèn)為"black";
* @return boolean
*/
function annotate($txt, $opacity, $gravity, array $font);
/**
* 將對(duì)象的數(shù)據(jù)重新初始化,用于多次重用一個(gè)Image_Tool對(duì)象
* @access public
* @return void
*/
function clean();
*
* 圖片合成,可以進(jìn)行多張圖片的合成,也可以做圖片水印用
* @access public
* @param int $src_img 合成的目標(biāo)圖片,可以為ImageTool對(duì)象或圖片二進(jìn)制數(shù)據(jù)
* @param int $x 合成在畫(huà)布的X坐標(biāo)
* @param string $y 合成在畫(huà)布的Y坐標(biāo)
* @return boolean
*
function composite($src_img, $x, $y);
/**
* 返回錯(cuò)誤信息
* @access public
* @return string
*/
function errmsg();
/**
* 返回錯(cuò)誤編號(hào)
* @access public
* @return int
*/
function errcode();
/**
* 進(jìn)行圖片處理操作
* @access public
* @param string $format
* @param boolean $display
* @return boolean|string 若設(shè)置$display為true,返回void,否則返回圖片二進(jìn)制數(shù)據(jù)。失敗時(shí)返回false
*/
function exec($format, $display=false);
/**
* 水平翻轉(zhuǎn)
* @access public
* @return boolean
*/
function flipH();
/**
* 垂直翻轉(zhuǎn)
* @access public
* @return boolean
*/
function flipV();
/**
* 取得圖片屬性
* @access public
* @return array|boolean 錯(cuò)誤返回false
*/
function getImageAttr();
/**
* 去噪點(diǎn),改善圖片質(zhì)量,通常用于exec之前
* @access public
* @return boolean
*/
function improve();
/**
* 縮放圖片,只指定width或者h(yuǎn)eight時(shí),將進(jìn)行等比縮放
* @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);
/**
* 順時(shí)針旋轉(zhuǎn)圖片
* @access public
* @param int $degree 旋轉(zhuǎn)度數(shù)(0 - 360)
* @return boolean
*/
function rotate($degree=90);
/**
* 設(shè)置要處理的圖片二進(jìn)制數(shù)據(jù)
* @access public
* @param string $img_blob
* @return boolean
*/
function setData($img_blob);
}
三、擴(kuò)展實(shí)現(xiàn)
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 */
源碼下載地址:http://l9.yunpan.cn/lk/QEcqyYY6zy9YR
相關(guān)文章
c語(yǔ)言實(shí)現(xiàn)詞頻統(tǒng)計(jì)的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇c語(yǔ)言實(shí)現(xiàn)詞頻統(tǒng)計(jì)的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-09-09基于C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單學(xué)生成績(jī)管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了基于C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單學(xué)生成績(jī)管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08OpenCV實(shí)現(xiàn)圖像去噪算法的步驟詳解
這篇文章主要為大家介紹了OpenCV中圖像去噪算法的原理,文中通過(guò)示例為大家詳細(xì)講解了圖像去噪算法的使用,感興趣的小伙伴可以了解一下2022-06-06Objective-C中常用的結(jié)構(gòu)體NSRange,NSPoint,NSSize(CGSize),NSRect實(shí)例分析
這篇文章主要介紹了Objective-C中常用的結(jié)構(gòu)體NSRange,NSPoint,NSSize(CGSize),NSRect實(shí)例分析,有助于更加直觀的理解Object-C常用的結(jié)構(gòu)體,需要的朋友可以參考下2014-07-07C++ Strassen算法代碼的實(shí)現(xiàn)
這篇文章主要介紹了C++ Strassen算法代碼的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03