php实现水印图功能__第1页
php实现水印图功能__第2页
php实现水印图功能__第3页
php实现水印图功能__第4页
php实现水印图功能__第5页
免费预览已结束,剩余3页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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 ); $_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; c

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论