1. 程式人生 > >TinyMCE外掛:Filemanager [4.x-6.x] 圖片自動新增水印

TinyMCE外掛:Filemanager [4.x-6.x] 圖片自動新增水印

上傳圖片程式(filemanager/upload.php)

if (!empty($_FILES) && $upload_files)有一個move_uploaded_file()函式,正是上傳圖片的源頭方法,在他成功執行將圖片成功上傳後,再加入水印方法即可。

if (!empty($_FILES) && $upload_files) {
    ....

    move_uploaded_file($tempFile, $targetFile);

    //一定要在move_uploaded_file()之後新增水印,因為之前圖片還沒有上傳
    //===========================水印圖片.S
$src_path = 'mark.png'; $dst_path = $targetFile; //建立圖片的例項 $dst = imagecreatefromstring(file_get_contents($dst_path)); $src = imagecreatefromstring(file_get_contents($src_path)); //獲取水印圖片的寬高 list($src_w, $src_h) = getimagesize($src_path); //獲取要加水印圖片的寬高 list($dst_w, $dst_h
) = getimagesize($dst_path); //將水印圖片複製到目標圖片上,最後個引數50是設定透明度,這裡實現半透明效果 //imagecopymerge($dst, $src, 10, 10, 0, 0, $src_w, $src_h, 50); //如果水印圖片本身帶透明色,則使用imagecopy方法 imagecopy($dst, $src, ($dst_w - $src_w - 10), ($dst_h - $src_h - 10), 0, 0, $src_w, $src_h); //輸出圖片 list($dst_w, $dst_h, $dst_type) = getimagesize
($dst_path); switch ($dst_type) { case 1://GIF header('Content-Type: image/gif'); imagegif($dst, $dst_path); break; case 2://JPG header('Content-Type: image/jpeg'); imagejpeg($dst, $dst_path, 100); break; case 3://PNG header('Content-Type: image/png'); imagepng($dst, $dst_path, 100); break; default: break; } imagedestroy($dst); imagedestroy($src); //===========================水印圖片.E .... }