php 缩略图增加水印,php 图片上传代码(具有生成缩略图与增加水印功能)
class upfile {
public $filepath = "www.111com.net/"; //上传文件存放文件夹
public $filesize = 1000000; //允许上传的大小
//如果要修改允许上传文件的类型 请搜索 【 switch ($upfiletype) { //文件类型 】
public $reimagesize = array (
true, //是否生成缩略图
400, //缩略图宽
300,//缩略图高
"" //缩略图存放文件夹 如果为空和当前要生成缩略图的文件在同一目录 文件前缀r_
); //是否生成缩略图 array(生成或不生成,缩略图宽,缩略图高,存放文件夹); 注意:存放文件夹后跟 '/'
public $india = true; //是否打水印 true打 false不打
public $indiaimage = ""; //水印图片地址为空则不打图片水印 如果有文字水印建议不要开启图片水印
public $indiaimagex = 100; //图片距离图片左边距离
public $indiaimagey = 10; //图片距离图片上面距离
public $indiatext = "www.111com.net"; //水印文字
public $fontsize = 6; //水印文字大小,1最小6最大
public $indiatextx = 10; //文字距离图片左边距离
public $indiatexty = 10; //文字距离图片上面距离
public $r = 250; //图片颜色三原色 $r红
public $g = 250; //$g绿
public $b = 250; //$b蓝
public $indiapath = ""; //加了水印的图片保存路径,如果为空就直接替代原来的图片
//开始上传处理
function uploadfile($upfile) {
if ($upfile == "") {
die("uploadfile:参数不足");
}
if (!file_exists($this->filepath)) {
mkdir($this->filepath);
}
$upfiletype = $upfile['type'];
$upfilesize = $upfile['size'];
$upfiletmpname = $upfile['tmp_name'];
$upfilename = $upfile['name'];
$upfileerror = $upfile['error'];
if ($upfilesize > $this->filesize) {
return false; //文件过大
}
switch ($upfiletype) { //文件类型
case 'image/jpeg' :
$type = 'jpg';
break;
case 'image/pjpeg' :
$type = 'jpg';
break;
case 'image/png' :
$type = 'png';
break;
case 'image/gif' :
$type = 'gif';
break;
}
if (!isset ($type)) {
return false; //不支持此类型
}
if (!is_uploaded_file($upfiletmpname) or !is_file($upfiletmpname)) {
return false;
; //文件不是经过正规上传的;
}
if ($this->upfileerror != 0) {
return false; //其他错误
}
if ($this->upfileerror == 0) {
if (!file_exists($upfiletmpname)) {
return false; //临时文件不存在
} else {
$filename = date("ymdhis", time() + 3600 * 8); //图片已当前时间命名
$filename = $this->filepath . $filename . "." . $type;
if (!move_uploaded_file($upfiletmpname, $filename)) {
return false; //文件在移动中丢失
} else {
if ($this->india == true) {
$this->goindia($filename, $type,true);
} else {
if ($this->reimagesize[0] == true) {
$this->goreimagesize($filename, $type);
} else {
return true; //上传成功!
unlink($upfiletmpname);
}
}
}
}
}
}
//添加水印处理
function goindia($filename, $filetype,$reimage=false) {
if (!file_exists($filename)) {
$this->reerror(7); //要添加水印的文件不存在
} else {
if ($filetype == "jpg") {
$im = imagecreatefromjpeg($filename);
} else
if ($filetype == "gif") {
$im = imagecreatefromgif($filename);
} else
if ($filetype == "png") {
$im = imagecreatefrompng($filename);
}
if ($this->indiatext != "") { //如果水印文字不为空
$textcolor = imagecolorallocate($im, $this->r, $this->g, $this->b); //设置文字颜色
imagestring($im, $this->fontsize, $this->indiatextx, $this->indiatexty, $this->indiatext, $textcolor); //将文字写入图片
}
if ($this->indiaimage != "") {//如果水印图片不为空
$indiaimagetype = getimagesize($this->indiaimage);
$logow = $indiaimagetype[0]; //得到水印图片的宽
$logoh = $indiaimagetype[1]; //得到水印图片的高
switch ($indiaimagetype[2]) { //判断水印图片的格式
case 1 :
$indiaimagetype = "gif";
$logo = imagecreatefromgif($this->indiaimage);
break;
case 2 :
$indiaimagetype = "jpg";
$logo = imagecreatefromjpeg($this->indiaimage);
break;
case 3 :
$indiaimagetype = "png";
$logo = imagecreatefrompng($this->indiaimage);
break;
}
imagealphablending($im, true); //打开混色模式
imagecopy($im, $logo, $this->indiaimagex, $this->indiaimagey, 0, 0, $logow, $logoh);
imagedestroy($im);
imagedestroy($logo);
}
}
if ($this->indiapath == "") { //如果水印存放地址不为空
if ($filetype == "jpg") {
imagejpeg($im, $filename);
} else
if ($filetype == "gif") {
imagegif($im, $filename);
} else
if ($filetype == "png") {
imagepng($im, $filename);
}
if($reimage == true){
$this->goreimagesize($filename,$filetype);
}else{
return true; //添加水印成功
}
} else {
if (!file_exists($this->indiapath)) {
mkdir($this->indiapath);
return false; //请重新上传
} else {
$indianame = basename($filename);
$indianame = $this->indiapath . $indianame;
if ($filetype == "jpg") {
imagejpeg($im, $indianame);
} else
if ($filetype == "gif") {
imagegif($im, $indianame);
} else
if ($filetype == "png") {
imagepng($im, $indianame);
}
if($reimage == true){
$this->goreimagesize($indianame,$filetype);
echo $indianame;
}else{
return true; //添加水印成功
}
}
}
}
function goreimagesize($filename, $filetype) {
if (!file_exists($filename)) {
return false; //要生成缩略图的图片不存在
} else {
if ($filetype == 'jpg') {
$reimage = imagecreatefromjpeg($filename);
}
elseif ($filetype == 'png') {
$reimage = imagecreatefrompng($filename);
} else
if ($filetype == 'gif') {
$reimage = imagecreatefromgif($filename);
}
if (isset ($reimage)) {
$srcimagetype = getimagesize($filename);
$srcimagetypew = $srcimagetype[0]; //得到原始图片宽度
$srcimagetypeh = $srcimagetype[1]; //得到原始图片高度
$reim = imagecreatetruecolor($this->reimagesize[1], $this->reimagesize[2]);
imagecopyresized($reim, $reimage, 0, 0, 0, 0, $this->reimagesize[1], $this->reimagesize[2], $srcimagetypew, $srcimagetypeh);
$reimagepath = $this->reimagesize[3];
if ($reimagepath != "") { //如果存放水印地址不为空
if (!file_exists($reimagepath)) {
mkdir($reimagepath);
} else {
$reimagename = basename($filename);
$reimagename = $reimagepath . "r_" . $reimagename;
if ($filetype == "gif")
imagegif($reim, $reimagename);
else
if ($filetype == "jpg")
imagejpeg($reim, $reimagename);
else
if ($filetype == "png")
imagepng($reim, $reimagename);
return true;
}
} else {
$filename = basename($filename);
if($this->indiapath == ""){
$filename = $this->filepath."r_" . $filename;
}else{
$filename = $this->indiapath."r_" . $filename;
}
if ($filetype == "gif")
imagegif($reim, $filename);
else
if ($filetype == "jpg")
imagejpeg($reim, $filename);
else
if ($filetype == "png")
imagepng($reim, $filename);
return true;
}
}
}
}
}
if ($_post["submit"]) {
$file = $_files['uploadfile'];
$upfile = new upfile();
echo $upfile->uploadfile($file);
}
?>
php 缩略图增加水印,php 图片上传代码(具有生成缩略图与增加水印功能)相关推荐
- php网页中不能上传图片,为什么我的PHP图片上传代码可以实现插入数据库但图片不能插入文件夹中?...
为什么我的PHP图片上传代码可以实现插入数据库但图片不能插入文件夹中? 关注:167 答案:4 mip版 解决时间 2021-01-19 00:58 提问者慢慢学会遗忘 2021-01-18 00 ...
- 利用Go语言上传图像并生成缩略图
承前文:Go语言中对图像进行缩放 //利用Go语言上传图像并生成缩略图 func upload(w http.ResponseWriter, req *http.Request, link strin ...
- html 头像选择,html5点击上传头像选取本地图片上传代码
特效描述:html5 点击上传头像 选取本地图片 上传代码.html5点击上传头像,图片上传代码 代码结构 1. HTML代码 上传头像 //获取上传按钮 var input1 = document. ...
- php 图片上传 水印,PHP - 图片上传并添加水印
一个的面向过程的 PHP 图片上传并对其添加文字水印的功能. 还有很多待需完善的地方. index.php $conn=@mysql_connect("localhost",&qu ...
- PHP图片加水印,然后将加水印的图片上传到七牛云
今天项目有这么一个需求,简单实现了一下,当然用起来是没有任何问题的,现在把实现代码分享给小伙伴们 public function uploadImgToQiniu($picture_id){$wate ...
- 图片上传时即时生成多个缩略图
在网上找了不少案例,都没有我理想的代码,我就根据其中一个改编成自己想要的功能,先附上最终效果. 代码如下,不难的,另外要加上jquery.js代码就可以了: <%@ page language= ...
- php上传图片并显示代码,php图片上传代码(完整版已测试)
php图片上传代码本来是一个很简单的事,之前笔者图省事,直接网上下载了一个php图片上传小程序,结果导致wordpress网站被黑,因为留有后门,后来排查直接删除整个小程序,自己用重新写了一个php图 ...
- 阿里OSS对象存储,实现图片上传代码;
一.注册阿里云账号,购买OSS服务 获取 : 连接区域地址endpoint :需要存储的bucketName:图片保存路径picLocation :连接keyId:accessKeyId :连接秘钥a ...
- 图片上传组件_配置Django-TinyMCE组件 实现上传图片功能
Django自带的Admin后台,好用,TinyMCE作为富文本编辑器,也蛮好用的,这两者结合起来在做博客的时候很方便(当然博客可能更适合用Markdown来写),但是Django-TinyMCE这个 ...
最新文章
- Ubuntu下自动挂载Windows分区的方法
- 架构漫谈 - 数据治理核心思路及解决方案探讨
- VS2008非托管c++访问webservice服务(以WeatherWS 天气服务 为例)
- 全国计算机c二级编程题,全国计算机二级C上机 编程题.doc
- laravel 集成采集_Laravel 使用 QueryList 轻松采集网页
- c语言表达式10 6的结果,C语言表达式(++i)+(++i)+(++i)结果多少?
- Python把PDF文件中每页内容分离为独立图片文件
- eclipse配置tomcat运行时访问路径不要项目名称
- 初次尝试使用VisualSFM记录
- linux recv函数 参数,linux send recv函数详解
- 相对湿度与绝对湿度转换表包含负温度
- 关于word中的DDE如何查看
- pytorch实现bnn
- Chrome 地址栏 Google 搜索错误处理 隐私设置错误 您的连接不是私密连接
- Excel 数据的统计分析及绘图自动处理的python示例(精益办公实战2)
- DSPE-PEG-LTLRWVGLMS(二硬脂酰基磷脂酰乙醇胺-聚乙二醇-肿瘤靶向蛋白);神经胶质瘤归巢肽
- hotmail服务器密码已修改密码,修改过密码的hotmail无法在mac和iphone上登陆和收取邮件...
- Perl Regular Expression Syntax Perl的正则表达式语法
- request.setAttribute理解
- java向上取整去掉末尾的0_BigDecimal去除末尾多余的0