您好,欢迎访问一九零五行业门户网

PHP上传图片进行等比缩放可增加水印功能_PHP教程

啥也不说,直接上代码,大家可以自行添加增加水印功能:
复制代码 代码如下:
1){
//宽度较大
if($imagewidth > $width){
//缩放图片到背景图片上
$new_width = $width;
$new_height = ($width*$imageheight)/$imagewidth;
$bg_y = ceil(abs(($height-$new_height)/2));
imagecopyresampled($bgimg, $im, 0, $bg_y, 0, 0, $new_width, $new_height, $imagewidth, $imageheight);
}else{
//复制图片到背景图片上
$copy = true;
}
}else{
//高度较大
if($imageheight > $height){
//缩放图片
$new_height = $height;
$new_width = ($height*$imagewidth)/$imageheight;
$bg_x = ceil(($width-$new_width)/2);
imagecopyresampled($bgimg, $im, $bg_x, 0, 0, 0, $new_width, $new_height, $imagewidth, $imageheight);
}else{
//复制图片到背景图片上
$copy = true;
}
}
if($copy){
//复制图片到背景图片上
$bg_x = ceil(($width-$imagewidth)/2);
$bg_y = ceil(($height-$imageheight)/2);
imagecopy($bgimg, $im, $bg_x, $bg_y, 0, 0, $imagewidth, $imageheight);
}
$ext = _file_type($mime);
$outfun($bgimg, $savepath.'/'.$ext);
imagedestroy($bgimg);
return $savepath.'/'.$ext;
}else{
return false;
}
}
if($_post){
$size = $_post['size']?strtoupper(trim($_post['size'])):'2m';
$imgsize = $_files['img']['size']?$_files['img']['size']/(1024*1024):0;
$imgwidth = $imgheight = $_post['width-height']?intval($_post['width-height']):300;
//自定定义文件上传大小
ini_set('upload_max_filesize',$size);
$mathsize = str_replace('m','',$size);
if($imgsize>$mathsize){
echo 图片大小不得超过{$size}!;
return;
}
if($file_name = _file_type($_files['img']['type'])){
if($_files['img']['error'] == upload_err_ok){
$savepath = 'upload/';
if(!is_dir($savepath)){
mkdir($savepath,0644);
}
//生成缩略图
$thumb_file = _make_thumb($_files['img']['tmp_name'], $imgwidth, $imgheight, $savepath);
//move_uploaded_file($_files['img']['tmp_name'],$savepath.$file_name);
echo 生成后的图片为:;
}else{
echo $_files['img']['error'];
return;
}
}else{
echo 图片格式不正确,请上传jpg,gif,png的格式!;
return;
}
}else{
echo
缩放图片保存成正方形
上传一张图片:
生成缩略图的宽高(单位px):
文件大小上限:
eot;
}
http://www.bkjia.com/phpjc/695103.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/695103.htmltecharticle啥也不说,直接上代码,大家可以自行添加增加水印功能: 复制代码 代码如下: ?php /** * * @author zhao jinhan * @date 2014年1月13日11:54:30 * @email...
其它类似信息

推荐信息