//mark.php加浮水印檔案 function go( $url, $t = 0 ) { exit( ( "<script language=網頁特效>settimeout("location.replace('".$url."')",".$t * 1000 ).")</script>" ); } function imagewatermark( $product_img, $waterpos = 0, $waterimage = "", $watertext = "", $textfont = 25, $textcolor = "#ff0000", $newdir = "marked" ) { echo "正在處理圖片:".$product_img."<br>"; $iswaterimage = false; $formatmsg = "暫不支援該檔案格式,請用圖片處理軟體將圖片轉換為gif、jpg、png格式。"; if ( !empty( $waterimage ) && file_exists( $waterimage ) ) { $iswaterimage = true; $water_info = getimagesize( $waterimage ); $water_w = $water_info[0]; $water_h = $water_info[1]; switch ( $water_info[2] ) { case 1 : $water_im = imagecreatefromgif( $waterimage ); break; case 2 : $water_im = imagecreatefromjpeg( $waterimage ); break; case 3 : $water_im = imagecreatefrompng( $waterimage ); break; default : echo $formatmsg; return; } } if ( !empty( $product_img ) && file_exists( $product_img ) ) { $ground_info = getimagesize( $product_img ); $ground_w = $ground_info[0]; $ground_h = $ground_info[1]; switch ( $ground_info[2] ) { case 1 : $ground_im = imagecreatefromgif( $product_img ); break; case 2 : $ground_im = imagecreatefromjpeg( $product_img ); break; case 3 : $ground_im = imagecreatefrompng( $product_img ); break; default : echo $formatmsg; return; } } else { exit( "需要加浮水印的圖片不存在!" ); } if ( $iswaterimage ) { $w = $water_w; $h = $water_h; $label = "圖片的"; } else { $temp = @imagettfbbox( @ceil( $textfont * 2.5 ), 0, "arial.ttf", $watertext ); $w = $temp[2] - $temp[6]; $h = $temp[3] - $temp[7]; unset( $temp ); $label = "文字地區"; } if ( $ground_w < $w || $ground_h < $h ) { echo "需要加浮水印的圖片的長度或寬度比浮水印".$label."還小,無法產生浮水印!"; } else { switch ( $waterpos ) { case 0 : $posx = rand( 0, $ground_w - $w ); $posy = rand( 0, $ground_h - $h ); break; case 1 : $posx = 0; $posy = 0; break; case 2 : $posx = ( $ground_w - $w ) / 2; $posy = 0; break; case 3 : $posx = $ground_w - $w; $posy = 0; break; case 4 : $posx = 0; $posy = ( $ground_h - $h ) / 2; break; case 5 : $posx = ( $ground_w - $w ) / 2; $posy = ( $ground_h - $h ) / 2; break; case 6 : $posx = $ground_w - $w; $posy = ( $ground_h - $h ) / 2; break; case 7 : $posx = 0; $posy = $ground_h - $h; break; case 8 : $posx = ( $ground_w - $w ) / 2; $posy = $ground_h - $h; break; case 9 : $posx = $ground_w - $w; $posy = $ground_h - $h; break; default : $posx = rand( 0, $ground_w - $w ); $posy = rand( 0, $ground_h - $h ); break; } imagealphablending( $ground_im, true ); imagecopyresampled($ground_im, $water_im,0,0, $posx, $posy, 0, 0, $water_w, $water_h); if ( $iswaterimage ) { imagecopymerge( $ground_im, $water_im, $posx, $posy, 0, 0, $water_w, $water_h,35 ); } else { if ( !empty( $textcolor ) && strlen( $textcolor ) == 7 ) { $r = hexdec( substr( $textcolor, 1, 2 ) ); $g = hexdec( substr( $textcolor, 3, 2 ) ); $b = hexdec( substr( $textcolor, 5 ) ); } else { exit( "浮水印文字顏色格式不正確!" ); } imagestring( $ground_im, $textfont, $posx, $posy, $watertext, imagecolorallocate( $ground_im, $r, $g, $b ) ,35); } switch ( $ground_info[2] ) { case 1 : imagegif( $ground_im, $newdir."/".$product_img ); break; case 2 : imagejpeg( $ground_im, $newdir."/".$product_img ); break; case 3 : imagepng( $ground_im, $newdir."/".$product_img ); break; default : echo $errormsg; } if ( isset( $water_info ) ) { unset( $water_info ); } if ( isset( $water_im ) ) { imagedestroy( $water_im ); } unset( $ground_info ); imagedestroy( $ground_im ); unset( $water_im ); unset( $ground_im ); } } set_time_limit( 0 ); include( "config.php" ); if ( $_get[id] ) { $id = $_get[id]; } else { $id = 1; } if ( !is_dir( $dir2."/".$dir1 ) ) { mkdir( $dir2."/".$dir1, 511 ); } $ti = 0; $dir = opendir( $dir1 ); while ( $file = readdir( $dir ) ) { if ( $file == "." || $file == ".." ) { } else { ++$ti; if ( $ti < ( $id - 1 ) * $per ) { } else { if ( ( $id - 1 ) * $per <= $ti && $ti < $id * $per ) { imagewatermark( $dir1."/".$file, $mark_pos, $mark_img, $mark_text, $mark_text_size, "#ff0000", $dir2 ); } if ( $id * $per <= $ti ) { closedir( $dir ); go( "mark.php?id=".( $id + 1 ) ); } } } } |