php实现水印图功能_.docx

上传人:啊飒飒 文档编号:11646270 上传时间:2021-08-27 格式:DOCX 页数:8 大小:12.66KB
返回 下载 相关 举报
php实现水印图功能_.docx_第1页
第1页 / 共8页
php实现水印图功能_.docx_第2页
第2页 / 共8页
php实现水印图功能_.docx_第3页
第3页 / 共8页
php实现水印图功能_.docx_第4页
第4页 / 共8页
php实现水印图功能_.docx_第5页
第5页 / 共8页
亲,该文档总共8页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《php实现水印图功能_.docx》由会员分享,可在线阅读,更多相关《php实现水印图功能_.docx(8页珍藏版)》请在三一文库上搜索。

1、php实现水印图功能_ php实现水印图功能. 测试水印的文件代码: ?php require( ./WaterMark.class.php ); $water = new WaterMark( ./images/psb.jpg, ./images/200(1).jpg ); $water-Exec( ./images/w.jpg, center-center ); ? 水印功能的文件代码: ?php /* * Add water stain to specified image * author pankai * date 2021-09-27 */ class WaterMark /* I

2、mage source path */ private $_src_path = NULL; private $_image_source = NULL; /* Water-Stain image source path */ private $_water_path = NULL; private $_water_source = NULL; private $_extension = NULL; public function _construct( $_src_path, $_water_path ) $this-_src_path = $_src_path; $this-_water_

3、path = $_water_path; /* * Get image source form image designated path * param $_img_path * return resource */ private function getImageSource( $_img_path ) $_path = explode( ., strtolower( $_img_path ) ); $_bak = strtoupper( $_path sizeof( $_path ) - 1 ); $_img_source = NULL; $this-_extension = $_ba

4、k; switch( $_bak ) case GIF: $_img_source = imagecreatefromgif( $_img_path ); break; case JPG: case JPEG: $_img_source = imagecreatefromjpeg( $_img_path ); break; case PNG: $_img_source = imagecreatefrompng( $_img_path ); break; case WBMP: $_img_source = imagecreatefromwbmp( $_img_path ); break; ret

5、urn $_img_source; /* * Count coordinate * param $direction string * return array */ private function countArgs( $_src, $_water, $_direction ) $_args = NULL; /* * Count the images width and images height * which are used to show Water-Stain image arbitrarily */ $src_x = imagesx( $_src ); $src_y = ima

6、gesy( $_src ); $water_x = imagesx( $_water ); $water_y = imagesy( $_water ); switch( strtolower( $_direction ) ) case top-left: $_args = array( 0, 0 ); break; case top-center: $_args = array( floor( ( $src_x - $water_x ) / 2 ), 0 ); break; case top-right: $_args = array( $src_x - $water_x, 0 ); brea

7、k; case center-left: $_args = array( 0, floor( ( $src_y - $water_y ) / 2 ) ); break; case center-center: $_args = array( floor( ( $src_x - $water_x ) / 2 ), floor( ( $src_y - $water_y ) / 2 ) ); break; case center-right: $_args = array( $src_x - $water_x, floor( ( $src_y - $water_y ) / 2 ) ); break;

8、 case bottom-left: $_args = array( 0, $src_y - $water_y ); break; case bottom-center: $_args = array( floor( ( $src_x - $water_x ) / 2 ), $src_y - $water_y ); break; case bottom-right: $_args = array( $src_x - $water_x, $src_y - $water_y ); break; return $_args; /* * The main programmer: copy Water-

9、Stain image source into specified image source, * then save this into appointed path * param $dst_name * return bool */ public function Exec( $dst_name, $direction = bottom-right ) $this-_image_source = $this-getImageSource( $this-_src_path ); $this-_water_source = $this-getImageSource( $this-_water

10、_path ); $water_x = imagesx( $this-_water_source ); $water_y = imagesy( $this-_water_source ); $_args = $this-countArgs( $this-_image_source, $this-_water_source, $direction ); $_copy = imagecopy( $this-_image_source, $this-_water_source, abs( $_args 0 ), abs( $_args 1 ), 0, 0, $water_x, $water_y );

11、 $_out = true; /* imagejpeg( $this-img_dst, $dst_name, 100 ); */ switch ( $this-_extension ) case GIF: $_out = imagegif( $this-_image_source, $dst_name ); break; case JPG: case JPEG: $_out = imagejpeg( $this-_image_source, $dst_name, 100 ); break; case PNG: $_out = imagepng( $this-_image_source, $dst_name ); break; case WBMP: $_out = imagewbmp( $this-_image_source, $dst_name ); return $_copy $_out; ? 更多信息请查看IT技术专栏 .

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1