📄 func.watermark.php
字号:
<?php/** Copyright (c) 2004 Heiko Rutenbeck <bzrudi@tuxpower.de>** This program is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation; either version 2 of the License, or* (at your option) any later version.** This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.** You should have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/if(!defined('TOP_DIR')) { define('TOP_DIR','../..'); }/*** @uses get_thumbs_on_fly.php, file_download.php* @author flo*/function need_watermark($imgid){ /*if(!isset($GLOBALS['passed'])) { $passed = false; } else { global $passed; }*/ if( read_plugins_config('watermark') && read_config('wm_active') && !check_permissions('watermark',$imgid) ) { return true; } else { return false; }}function array_watermark(){/*############################################################ used in: many!## returns:## array with all the configs and the default values, they are only defined here##########################################################*/ $arr_config = array ( 'wm_active' => "0", 'wm_watermark' => "0", 'wm_text' => "Copyright 2004", 'wm_font' => "", 'wm_fontsize' => "20", 'wm_fontcolor' => "white", 'wm_align' => "southwest", 'wm_horizontal' => "0", 'wm_vertical' => "0", 'wm_enable_shadow' => "1", 'wm_shadow_size' => "1", 'wm_shadow_fontsize' => "20", 'wm_shadow_color' => "black", 'wm_enable_rectangle' => "1", 'wm_rectangle_color' => "darkgrey", 'wm_height' => "30", 'wm_width' => "145", 'wm_img_img' => "", 'wm_dissolve' => "75%", 'wm_resize' => "30" ); return $arr_config;}function read_watermark(){ $arr_config = array_watermark(); while(list($name,$value) = each($arr_config) ) { $arr_read[$name] = read_config($name); } return $arr_read;}function update_watermark(){ if(get_magic_quotes_runtime()) { $_POST['wm_text'] = stripslashes($_POST['wm_text']); } $arr_config = array_watermark(); while(list($name,$value) = each($arr_config) ) { update_config($_POST[$name], $name); }}function wm_arr_resized($w,$h,$org_width,$org_height,$resize){/*############################# used in: build_watermark_str() and watermark_gd()## calcs the new height and width of the resized watermark## $w, $h: size of the big image## $org_width, $org_height: size of the watermark rectangle/image## $resize: resize factor in percent###########################*/ $arr_resized['w'] = round($w * $resize/100); $arr_resized['h'] = round($h * $resize/100); $no_increase = 0; $array = scale_to_fit($org_height,$org_width,$arr_resized['h'],$arr_resized['w'],$no_increase); //error_log('w: '.$w.' h: '.$h.' arr_resized_w: '.$arr_resized['w'].' arr_resized_h: '.$arr_resized['h']. // ' org_w: '.$org_width.' org_h: '.$org_height.' scale_to_fit w: '.$array['w'].' h: '.$array['h']); return $array;}function build_watermark_str($input,$output,$q,$w,$h,$convert_path){/*############################# used in: convert_image_convert()###########################*/ if(isset($GLOBALS['wm_config'])) { $wm_config = $GLOBALS['wm_config']; } else { $wm_config = read_watermark(); } $align_str = ' -gravity '.$wm_config['wm_align']; $dissolve_str = ' -dissolve '.$wm_config['wm_dissolve']; /** * check wether brackets are needed or not * details see sec_stage_install.php */ if(getOS()=="win") { $bracket_escape = ''; } else { $bracket_escape = '\\'; } if(read_config('im_bracket_support')) { $bracket_start = $bracket_escape.'( '; $bracket_end = ' '.$bracket_escape.')'; } else { $bracket_start = ''; $bracket_end = ''; } switch($wm_config['wm_watermark']) { case 0: //#### Disabled #### // if making any changes, change it in the function convert_image_convert() too! $convert_str = $convert_path.'convert'. ' -quality '.$q. ' -size "'.$w.'x'.$h.'"'. // new size ' '.escape_string($input).'[0]'. // [0] -> take only first frame!!! ' -resize "'.$w.'x'.$h.'"'. // new size ' -strip '. // replaces +profile "*" this should be save to use, as it's available since Jun 2003 ' ' -colorspace RGB'. // change colorspace always to RGB because all browsers only can display RGB images ' '.escape_string($output); break; case 1: //#### Text ##### //## Rectangle if($wm_config['wm_enable_rectangle']==1) { $rect_str = ' -fill "'.$wm_config['wm_rectangle_color'].'"'. // rectangle color ' -draw "rectangle 0,0,'.$wm_config['wm_width'].','.$wm_config['wm_height'].'"'; // rectangle itself } else { $rect_str = ""; } //## Font if($wm_config['wm_font']=="no") { $font_str = ''; // no ttf files found, try without setting the font parameter (on my linux server it has produced an error, on windows it has worked...) } else { $font_str = ' -font '.TOP_DIR.'"/plugins/watermark/font/'.$wm_config['wm_font'].'.ttf"'; } //## Text and Shadow $fontsize_str = ' -pointsize '.$wm_config['wm_fontsize']; // normal or no shadow if($wm_config['wm_enable_shadow'] == 1) { $draw_str = ' -pointsize '.$wm_config['wm_shadow_fontsize']. // Shadow fontsize ' -draw "fill '.$wm_config['wm_shadow_color']. // Shadow color ' text 0,0 \''.$wm_config['wm_text'].'\'"'. // Shadow itself $fontsize_str. // Text fontsize ' -draw "fill '.$wm_config['wm_fontcolor']. // Text color ' text '.$wm_config['wm_shadow_size'].','.$wm_config['wm_shadow_size'].' \''.$wm_config['wm_text'].'\'"'; // Text itself } // extended shadow elseif($wm_config['wm_enable_shadow'] == 2) { $draw_str = $fontsize_str. // Text fontsize ' -stroke '.$wm_config['wm_shadow_color']. // Shadow color ' -strokewidth '.$wm_config['wm_shadow_size']. // Shadow fontsize ' -draw "text 0,0 \''.$wm_config['wm_text'].'\'"'. // Shadow itself ' -gaussian 0x3 -stroke none'. // Extended Shadow ' -fill '.$wm_config['wm_fontcolor']. // Text color ' -draw "text 0,0 \''.$wm_config['wm_text'].'\'"'; // Text itself } //## Scale watermark always to X% of image size - Stuff if($wm_config['wm_resize']!="no") { $arr_resized = wm_arr_resized($w,$h,$wm_config['wm_width'],$wm_config['wm_height'],$wm_config['wm_resize']); $convert_str_part1 = $convert_path.'convert'. ' -quality 100'. ' "-"'. ' -resize "'.$arr_resized['w'].'x'.$arr_resized['h'].'"'. ' miff:- | '; } else { $convert_str_part1 = ''; } //## The magic convert - stuff $convert_str = $convert_path.'convert'. ' -quality 100'. // quality 100, this is only for the small rectangle $font_str. ' -size '.$wm_config['wm_width'].'x'.$wm_config['wm_height']. ' xc:none'. // ? (this slows down watermark..?! (maybe)) $rect_str. // if rectangle is enabled, it will be shown here ' -gravity center'. // align of text in the smell rectangle is always center $draw_str. // draw the text with shadow ' miff:- | '. // not to output, but to pipe '|' so that is for the input for the program 'composite' which is also part of the convert program, this program can merge two images $convert_str_part1. // Scale watermark always to X% of image size - Stuff $convert_path.'composite'. ' -quality '.$q. // here is the real quality string ' -size "'.$w.'x'.$h.'"'. // new size $dissolve_str. $align_str. ' -geometry +'.$wm_config['wm_horizontal'].'+'.$wm_config['wm_vertical']. // adjust the image with the specified paramters ' -type TruecolorMatte'. ' "-" '. // watermark image "input from pipe" ' '.$bracket_start.escape_string($input).'[0]'. // [0] -> take only first frame!!! // input file ' -resize "'.$w.'x'.$h.'"'.$bracket_end. // new size (the values are the same like $size_str) ' +profile "*"'. // delete all profiles (-strip isn't available in imagemagick < 6.0) ' -colorspace RGB'. // change colorspace always to RGB because all browsers only can display RGB images ' '.escape_string($output); // output break; case 2: //#### Image #### //## Watermark image if($wm_config['wm_img_img']=="no") { // no image found, to prevent an error, take the same image as watermark and as input $img_path = $input; $wm_img_str = ' '.$img_path; // no '"' before and after $img_path because it is already escaped! } else { if(file_exists($wm_config['wm_img_img'])) // needed for creating video thumbnails { $img_path = $wm_config['wm_img_img']; $wm_img_str = ' "'.$img_path.'"'; } else { $img_path = TOP_DIR.'/plugins/watermark/watermarks/'.$wm_config['wm_img_img']; $wm_img_str = ' "'.$img_path.'"'; } } //## Scale watermark always to X% of image size if($wm_config['wm_resize']!="no") { list($org_width,$org_height,$org_type) = linpha_getimagesize($img_path); $arr_resized = wm_arr_resized($w,$h,$org_width,$org_height,$wm_config['wm_resize']); // calculate the size of the resized watermark image $convert_str_part1 = $convert_path.'convert'. ' -quality 100'. // quality 100, this is only for the small image $wm_img_str. // input ' -resize "'.$arr_resized['w'].'x'.$arr_resized['h'].'"'. // resize watermark image ' miff:- | '; // output to 'pipe' $wm_img_str = ' "-"'; // new input from 'pipe' } else { $convert_str_part1 = ''; // no resize } //## The magic convert - stuff $convert_str = $convert_str_part1. $convert_path.'composite'. ' -quality '.$q. // here is the real quality string ' -size "'.$w.'x'.$h.'"'. // new size $dissolve_str. $align_str. ' -geometry +'.$wm_config['wm_horizontal'].'+'.$wm_config['wm_vertical']. // adjust the image with the specified paramters $wm_img_str. // if the wm image is resized, it's "-" ' '.$bracket_start.escape_string($input).'[0]'. // [0] -> take only first frame!!! // input ' -resize "'.$w.'x'.$h.'"'.$bracket_end. // new size ' +profile "*"'. // delete all profiles ' -colorspace RGB'. // change colorspace always to RGB because all browsers only can display RGB images ' '.escape_string($output); // output break; } //linpha_log("thumbnail","notice","convert_str: $convert_str"); return $convert_str;}function watermark_gd(&$scaled_image,$w,$h){ if(isset($GLOBALS['wm_config'])) { $wm_config = $GLOBALS['wm_config']; } else { $wm_config = read_watermark(); } if($wm_config['wm_watermark']!=0) { switch($wm_config['wm_watermark']) { case 1: //#### Text #### //## Font heigth and width $font_height = imagefontheight($wm_config['wm_fontsize']); $font_width = imagefontwidth($wm_config['wm_fontsize']); $string_width = strlen($wm_config['wm_text'])*$font_width; $string_height = $font_height; //## Create image $wm_img = imagecreate($wm_config['wm_width'], $wm_config['wm_height']); //## Colors $array_rgb = get_rgb_from_all($wm_config['wm_shadow_color']); $shadow_color = ImageColorAllocate($wm_img, $array_rgb['r'], $array_rgb['g'], $array_rgb['b']); $array_rgb = get_rgb_from_all($wm_config['wm_fontcolor']); $text_color = ImageColorAllocate($wm_img, $array_rgb['r'], $array_rgb['g'], $array_rgb['b']); //## Rectangle if($wm_config['wm_enable_rectangle']) { $array_rgb = get_rgb_from_all($wm_config['wm_rectangle_color']); $rect_col = ImageColorAllocate($wm_img, $array_rgb['r'], $array_rgb['g'], $array_rgb['b']); imagefill($wm_img, 0, 0, $rect_col); } //## Text $pos_x = ($wm_config['wm_width']-$string_width)/2; $pos_y = ($wm_config['wm_height']-$string_height)/2; imagestring($wm_img, $wm_config['wm_shadow_fontsize'], $pos_x, $pos_y, $wm_config['wm_text'], $shadow_color); imagestring($wm_img, $wm_config['wm_fontsize'], $pos_x+($wm_config['wm_shadow_size']), $pos_y+($wm_config['wm_shadow_size']), $wm_config['wm_text'], $text_color); //## Position on the big image $src_w = $wm_config['wm_width']; $src_h = $wm_config['wm_height']; break; case 2: //#### Image #### if(file_exists($wm_config['wm_img_img'])) // needed for creating video thumbnails { $wm_file = $wm_config['wm_img_img']; } else { $wm_file = TOP_DIR.'/plugins/watermark/watermarks/'.$wm_config['wm_img_img']; } list($wm_img_width,$wm_img_height,$wm_img_type) = linpha_getimagesize($wm_file); switch($wm_img_type) { case 1: $wm_img=imagecreatefromgif($wm_file); break; case 2: $wm_img=imagecreatefromjpeg($wm_file); break; case 3: $wm_img=imagecreatefrompng($wm_file); break; default: $wm_img=imagecreatefromjpeg($wm_file); break; } $src_w = $wm_img_width; $src_h = $wm_img_height; break; } //## Scale watermark always to X% of image size if($wm_config['wm_resize']!='no') { $arr_resized = wm_arr_resized($w,$h,$src_w,$src_h,$wm_config['wm_resize']); $resized_image=imagecreate($arr_resized['w'],$arr_resized['h']); imagecopyresized($resized_image,$wm_img,0,0,0,0, $arr_resized['w'],$arr_resized['h'],$src_w,$src_h); $src_w = $arr_resized['w']; $src_h = $arr_resized['h']; // Overwrite $wm_img with the resized image $wm_img = $resized_image; } //## Merge watermark image into scaled image $src_x = 0; $src_y = 0; $arr_pos = calc_align($wm_config['wm_align'],$src_w,$src_h, $w, $h, $wm_config['wm_horizontal'], $wm_config['wm_vertical']); imagecopymerge($scaled_image, $wm_img, $arr_pos['x'], $arr_pos['y'], $src_x, $src_y, $src_w, $src_h, $wm_config['wm_dissolve']); }}function restore_watermark(){/*############################################################ used in: watermark.php## restore watermark settings to initial settings## or to examples##########################################################*/ GLOBAL $wm_restore_to; $arr_config = array_watermark(); switch($_POST['setdefault']) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -