//缩小
public function trunsmall($arg=2,$savename=''){
$this->imgload();
if($savename=='')$savename='s_'.$this->filename;
$imgwidth=$this->info[0]; //原图宽
$imgheight=$this->info[1]; //原图高
$arg2= sqrt($arg); //缩小度 等比例
$imgwidth2=$imgwidth/$arg2; //新图宽
$imgheight2=$imgheight/$arg2; //新图高
if($arg>1 && $arg<10){
$img = imagecreatetruecolor($imgwidth2, $imgheight2);
imagecopyresized($img,$this->im,0,0,0,0,$imgwidth2,$imgheight2,$imgwidth,$imgheight);
$this->imagesave($img,$savename,$this->info[2]); //写文件
imagedestroy($img);
imagedestroy($this->im);
return 1;
}else{
imagedestroy($this->im);
return 0;}
}
//文字水印
public function printstr($str,$savename=''){
$this->imgload();
if($savename=='')$savename='p_'.$this->filename;
$imgwidth=$this->info[0]; //原图宽
$imgheight=$this->info[1]; //原图高
$x=$imgwidth/8; //x
$y=$imgheight/2; //y
$white = imagecolorallocate($this->im, 255, 255, 255);
$grey1 = imagecolorallocate($this->im, 150, 150, 150);
$grey2 = imagecolorallocate($this->im, 140, 140, 140);
$font = 'c:/windows/fonts/simkai.ttf';
if(is_file($font)){
$str = iconv("gb2312","utf-8",$str);
imagettftext($this->im, 14, 10, $x, $y, $grey1, $font, $str);
imagettftext($this->im, 14, 10, $x+1, $y+1, $grey2, $font, $str);
$this->imagesave($this->im,$savename,$this->info[2]); //写文件
imagedestroy($this->im);
return 1;
}else{
imagedestroy($this->im);
return 0;}
}
//小图章水印
public function imageadd($image,$savename=''){
$this->imgload();
if($savename=='')$savename='i_'.$this->filename;
if(!$image){return 0;exit;}
$imgwidth=$this->info[0]; //原图宽
$imgheight=$this->info[1]; //原图高
$imageinfo = getimagesize($image); //小图章
if($imageinfo[2]>3){return 0;exit;}
switch($imageinfo[2]){
case 1:
$img=@imagecreatefromgif($image);
break;
case 2:
$img=@imagecreatefromjpeg($image);
break;
case 3:
$img=@imagecreatefrompng($image);
break;
}
$imgwidth2=$imageinfo[0]; //小图宽
$imgheight2=$imageinfo[1]; //小图高
if($imgwidth2>$imgwidth/2 || $imgheight2>$imgheight/2){echo "小图章太大";exit;}
if(imagecopy ( $this->im, $img, ($imgwidth-$imgwidth2)/8, ($imgheight-$imgheight2)/8, 0, 0, $imgwidth2, $imgheight2 )){
$this->imagesave($this->im,$savename,$this->info[2]); //写文件
imagedestroy($img);
imagedestroy($this->im);
return 1;
}else{
imagedestroy($img);
imagedestroy($this->im);
return 0;
}
}
|