分类:PHP记事本 发布时间:2017-05-30 10:39:44 阅读: 作者:郑祥景
<?php
header("Content-type: text/html; charset=utf-8");
$filename="./images/zaixiankefu.jpg";
function thumn($background,$width/*要缩放的宽度*/,$newfile) { //等比例缩放图片
list($s_w, $s_h)=getimagesize($background);//获取原图片高度、宽度
$height = ($width / $s_w)* $s_h;
$new=imagecreatetruecolor($width, $height);//创建图片
$img=imagecreatefrompng($background);//加载图片
imagecopyresampled($new, $img, 0, 0, 0, 0, $width, $height, $s_w, $s_h);//裁剪图片
$newt=imagecolorallocate($new,0,0,0);
imagecolortransparent($new,$newt);
imagepng($new, $newfile);//创建新图片
imagedestroy($new);//销毁图像资源
imagedestroy($img);
}
//thumn($filename,50, "./images/shuiyin_chuli.png");
function cut($background, $cut_x, $cut_y, $cut_width, $cut_height, $location){//裁剪图片
list($s_w, $s_h)=getimagesize($background);
if($cut_height > $s_h){
$cut_height = $s_h;//判断若裁剪尺寸大于原尺寸,保持原尺寸
}else{//判断偏移量,裁剪图片正中心
$cut_y = ($s_h-$cut_height)/2;
}
if($cut_width > $s_w){//判断若裁剪尺寸大于原尺寸,保持原尺寸
$cut_width = $s_w;
}else{//判断偏移量,裁剪图片正中心
$cut_x = ($s_w - $cut_width)/2;
}
$back=imagecreatefromjpeg($background);
$new=imagecreatetruecolor($cut_width, $cut_height);
imagecopyresampled($new, $back, 0, 0, $cut_x, $cut_y, $cut_width, $cut_height,$cut_width,$cut_height);
imagejpeg($new, $location);
imagedestroy($new);
imagedestroy($back);
}
//cut($filename,0,0,50,50, "./images/zaixiankefu_chuli.jpg");
function mark_text($background, $text, $x, $y,$newfile){
$back=imagecreatefromjpeg($background);
$color=imagecolorallocate($back, 0, 255, 0); //为一幅图像分配颜色,这里设置文字水印的颜色
imagettftext($back, 20, 0, $x, $y, $color, 'font/arial.ttf', $text);
imagejpeg($back,$newfile);
imagedestroy($back);
}
//mark_text($filename, "PHP", 150, 250,"./images/zaixiankefu_chuli.jpg");
function mark_pic($background, $waterpic, $x, $y,$newfile){//加图片水印,根据图片大小调整水印大小
list($s_w, $s_h)=getimagesize($waterpic);
list($i_w, $i_h)=getimagesize($background);
$width = $i_w * 0.3;
$height = ($width / $s_w)* $s_h;
$new=imagecreatetruecolor($width, $height);//创建图片
$water=imagecreatefrompng($waterpic);
imagecopyresampled($new, $water,0,0, 0, 0,$width,$height, $s_w, $s_h);//裁剪图片
$newt=imagecolorallocate($new,0,0,0);
imagecolortransparent($new,$newt);
imagepng($new,'./images/shuiyin_chuli.png');//输出经过比例缩小的水印
imagedestroy($water);
$back=imagecreatefromjpeg($background);
$shuiyin = './images/shuiyin_chuli.png';//设置真实水印的大小
$shuiyin_ture =imagecreatefrompng($shuiyin);
$x = $i_w * 0.65;
$y = $i_h * 0.7;
imagecopy($back,$shuiyin_ture,$x,$y,0,0,$width,$height);
imagejpeg($back,$newfile);
imagedestroy($back);
}
//mark_pic($filename, "./images/shuiyin.png",0 ,0 ,"./images/zaixiankefu_chuli.jpg");
?>
<p>处理前:<img src='<?php echo $filename; ?>' /></p>
<p>处理后:<img src='/images/zaixiankefu_chuli.jpg';' /></p>
编辑:郑祥景