图片加上标签 exec( './images/w.jpg', 'center-center' );?>
_src_path = $_src_path; $this->_water_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 = $_bak; 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; } return $_img_source; } /** * count coordinate * @param $direction string * @return array */ private function countargs( &$_src, &$_water, $_direction ) { $_args = null; /** * count the image's width and image's height * which are used to show water-stain image arbitrarily */ $src_x = imagesx( $_src ); $src_y = imagesy( $_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 ); break; 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; 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-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_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; case 'png': $_out = imagepng( $this->_image_source, $dst_name ); break; case 'wbmp': $_out = imagewbmp( $this->_image_source, $dst_name ); } return $_copy && $_out; }}?>
