Upimages.class.php php上传类
复制代码 代码如下:
class UpImages {
var $annexFolder = "upload";//附件存放点,默认为:annex
var $smallFolder = "small";//缩略图存放路径,注:必须是放在 $annexFolder下的子目录,默认为:smallimg
var $markFolder = "mark";//水印图片存放处
var $upFileType = "jpg gif png";//上传的类型,默认为:jpg gif png rar zip
var $upFileMax = 1024;//上传大小限制,单位是“KB”,默认为:1024KB
var $fontType;//字体
var $maxWidth = 500; //图片最大宽度
var $maxHeight = 600; //图片最大高度
function UpImages($annexFolder,$smallFolder,$includeFolder) {
$this->annexFolder = $annexFolder;
$this->smallFolder = $smallFolder;
$this->fontType = $includeFolder."/04B_08__.TTF";
}
function upLoad($inputName) {
$imageName = time();//设定当前时间为图片名称
if(@empty($_FILES[$inputName]["name"])) die("没有上传图片信息,请确认");
$name = explode(".",$_FILES[$inputName]["name"]);//将上传前的文件以“.”分开取得文件类型
$imgCount = count($name);//获得截取的数量
$imgType = $name[$imgCount-1];//取得文件的类型
if(strpos($this->upFileType,$imgType) === false) die(error("上传文件类型仅支持 ".$this->upFileType." 不支持 ".$imgType));
$photo = $imageName.".".$imgType;//写入数据库的文件名
$uploadFile = $this->annexFolder."/".$photo;//上传后的文件名称
$upFileok = move_uploaded_file($_FILES[$inputName]["tmp_name"],$uploadFile);
if($upFileok) {
$imgSize = $_FILES[$inputName]["size"];
$kSize = round($imgSize/1024);
if($kSize > ($this->upFileMax*1024)) {
@unlink($uploadFile);
die(error("上传文件超过 ".$this->upFileMax."KB"));
}
} else {
die(error("上传图片失败,请确认你的上传文件不超过 $upFileMax KB 或上传时间超时"));
}
return $photo;
}
function getInfo($photo) {
$photo = $this->annexFolder."/".$photo;
$imageInfo = getimagesize($photo);
$imgInfo["width"] = $imageInfo[0];
$imgInfo["height"] = $imageInfo[1];
$imgInfo["type"] = $imageInfo[2];
$imgInfo["name"] = basename($photo);
return $imgInfo;
}
function smallImg($photo,$width=128,$height=128) {
$imgInfo = $this->getInfo($photo);
$photo = $this->annexFolder."/".$photo;//获得图片源
$newName = substr($imgInfo["name"],0,strrpos($imgInfo["name"], "."))."_thumb.jpg";//新图片名称
if($imgInfo["type"] == 1) {
$img = imagecreatefromgif($photo);
} elseif($imgInfo["type"] == 2) {
$img = imagecreatefromjpeg($photo);
} elseif($imgInfo["type"] == 3) {
$img = imagecreatefrompng($photo);
} else {
$img = "";
}
if(empty($img)) return False;
$width = ($width > $imgInfo["width"]) ? $imgInfo["width"] : $width;
$height = ($height > $imgInfo["height"]) ? $imgInfo["height"] : $height;
$srcW = $imgInfo["width"];
$srcH = $imgInfo["height"];
if ($srcW * $width > $srcH * $height) {
$height = round($srcH * $width / $srcW);
} else {
$width = round($srcW * $height / $srcH);
}
if (function_exists("imagecreatetruecolor")) {
$newImg = imagecreatetruecolor($width, $height);
ImageCopyResampled($newImg, $img, 0, 0, 0, 0, $width, $height, $imgInfo["width"], $imgInfo["height"]);
} else {
$newImg = imagecreate($width, $height);
ImageCopyResized($newImg, $img, 0, 0, 0, 0, $width, $height, $imgInfo["width"], $imgInfo["height"]);
}
if ($this->toFile) {
if (file_exists($this->annexFolder."/".$this->smallFolder."/".$newName)) @unlink($this->annexFolder."/".$this->smallFolder."/".$newName);
ImageJPEG($newImg,$this->annexFolder."/".$this->smallFolder."/".$newName);
return $this->annexFolder."/".$this->smallFolder."/".$newName;
} else {
ImageJPEG($newImg);
}
ImageDestroy($newImg);
ImageDestroy($img);
return $newName;
}
function waterMark($photo,$text) {
$imgInfo = $this->getInfo($photo);
$photo = $this->annexFolder."/".$photo;
$newName = substr($imgInfo["name"], 0, strrpos($imgInfo["name"], ".")) . "_mark.jpg";
switch ($imgInfo["type"]) {
case 1:
$img = imagecreatefromgif($photo);
break;
case 2:
$img = imagecreatefromjpeg($photo);
break;
case 3:
$img = imagecreatefrompng($photo);
break;
default:
return False;
}
if (empty($img)) return False;
$width = ($this->maxWidth > $imgInfo["width"]) ? $imgInfo["width"] : $this->maxWidth;
$height = ($this->maxHeight > $imgInfo["height"]) ? $imgInfo["height"] : $this->maxHeight;
$srcW = $imgInfo["width"];
$srcH = $imgInfo["height"];
if ($srcW * $width > $srcH * $height) {
$height = round($srcH * $width / $srcW);
} else {
$width = round($srcW * $height / $srcH);
}
if (function_exists("imagecreatetruecolor")) {
$newImg = imagecreatetruecolor($width, $height);
ImageCopyResampled($newImg, $img, 0, 0, 0, 0, $width, $height, $imgInfo["width"], $imgInfo["height"]);
} else {
$newImg = imagecreate($width, $height);
ImageCopyResized($newImg, $img, 0, 0, 0, 0, $width, $height, $imgInfo["width"], $imgInfo["height"]);
}
$white = imageColorAllocate($newImg, 255, 255, 255);
$black = imageColorAllocate($newImg, 0, 0, 0);
$alpha = imageColorAllocateAlpha($newImg, 230, 230, 230, 40);
ImageFilledRectangle($newImg, 0, $height-26, $width, $height, $alpha);
ImageFilledRectangle($newImg, 13, $height-20, 15, $height-7, $black);
ImageTTFText($newImg, 4.9, 0, 20, $height-14, $black, $this->fontType, $text[0]);
ImageTTFText($newImg, 4.9, 0, 20, $height-6, $black, $this->fontType, $text[1]);
if($this->toFile) {
if (file_exists($this->annexFolder."/".$this->markFolder."/".$newName)) @unlink($this->annexFolder."/".$this->markFolder."/".$newName);
ImageJPEG($newImg,$this->annexFolder."/".$this->markFolder."/".$newName);
return $this->annexFolder."/".$this->markFolder."/".$newName;
} else {
ImageJPEG($newImg);
}
ImageDestroy($newImg);
ImageDestroy($img);
return $newName;
}
}
?>
使用方法
复制代码 代码如下:
include 'Upimages.class.php';
$max="upload"; //文件上传路径
$mix="small"; //缩略图路径(必须在upload下建立)
$mark="mark"; //加水引的图片存放路径
$text = array("oktang","2012"); //水印内容
$img= new UpImages($max,$mix,$max); //实例化类文件
$photo = $img->upLoad("file"); //上传的文件域
$img->maxWidth = $img->maxHeight = 600; //设置高,和宽
$img->toFile = true;
$newSmallImg = $img->smallImg($photo);
$newMark = $img->waterMark($photo,$text);
echo $newSmallImg;
echo $newMark;
echo "
";
echo "
";
注意里面有个字体文件,大家可以从网上下载。

你们在办公中是不是也在使用AdobeAcrobatPro9软件?不过你们知道AdobeAcrobatPro9怎样插入图片吗?下文小编就为大伙带来了AdobeAcrobatPro9插入图片的方法,感兴趣的一同来下文看看吧。在AdobeAcrobatPro9中打开Sample.pdf文档,点开文档右边的“工具”-“内容”-选择“编辑对象”,鼠标光标变成实心箭头+右下角小方框。右键单击文档空白处,然后选择“插入图像”。一个对话框会弹出,接着在对话框中选择ElenaGilbert.JPEG图像文件(请确

大家知道MicrosoftExcel怎么拆分单元格吗?下文小编就带来了MicrosoftExcel拆分单元格的方法,希望对大家能够有所帮助,一起跟着小编来学习一下吧!1、首先打开有着合并单元格的excel表格,如下图所示。2、选中合并单元格,点击顶部“合并居中”带向下箭头位置,如下图所示。3、然后去选择“取消合并单元格”,如下图所示。4、现在就可以发现单元格被拆分了,如下图所示。上面就是小编为大家带来的MicrosoftExcel怎么拆分单元格的全部内容,希望对大家能够有所帮助哦。

不少用户在选购一款手表和手环的时候都会比较纠结是买小米手环8pro还是华为手环8,二者之间的区别也是有不同的,如果你更看重体验,那么可以选择小米,如果你更看重健康监测,那么可以选择华为。小米手环8pro和华为手环8哪个好答:具体看需求。小米手环8pro:适合喜欢丰富的运动模式和更好的兼容性,以及有着接近手表的屏幕显示和颜值。华为手环8:更看重健康监测数据,也更看重无感的佩戴体验。当然还有一点就是,如果你的小米设备比较多,那么还是优先选择小米手环,如果你有华为手机,那么就选择华为手环。小米手环8P

红米RedmiK70Pro是当下最热门的高性价机型,搭载了最新的高通骁龙8Gen3处理器,也是当下最便宜的高通骁龙8Gen3手机,对于性能配置有要求但钱又不是很多的小伙伴都选择了这款手机。那么红米RedmiK70Pro出现了耗电快的情况应该怎么处理呢?红米RedmiK70Pro耗电快怎么办?如果你发现红米RedmiK70Pro耗电速度异常快,你可以尝试以下方法来减少耗电速度:方法一:调整亮度和屏幕超时时间将屏幕亮度调低,并将屏幕超时时间设置为较短的时间段,可以减少屏幕的能耗。方法二:关闭不必要的

红米RedmiK70是很多用户们都在使用的机型,这款手机自从发布以来一直都保持着很不错的口碑,拥有着超高的性价比。当然,除了性价比以外,红米RedmiK70还有着许多非常实用的功能。那么红米RedmiK70怎么打开存储权限呢?接下来就让小编来为大家介绍一下吧!红米RedmiK70怎么打开存储权限?要打开红米RedmiK70的存储权限,你可以按照以下步骤操作:步骤一:打开手机的设置应用。步骤二:向下滚动并找到“应用管理”或“应用和通知”,然后点击进入。步骤三:在应用管理中,找到你想要打开存储权限的

很多用户都在使用CorelDrawX4软件,不过你们晓得CorelDrawX4怎样绘制圆柱体吗?下文小编就为大伙带来了CorelDrawX4绘制圆柱体的方法,感兴趣的用户快来下文看看吧。打开CorelDRAWX4软件设置页面长594mm,宽297mm。点击矩形工具设置长100mm宽170mm,坐标x:250mm,y:160mm。2点击椭圆工具在矩形右边适当位置处绘制椭圆,长轴100mm,短轴60mm,并按Ctrl+D键复制一个。移动一个椭圆到矩形底边,坐标x:250mm,y:75mm。1点击菜单

rx5808g安装什么驱动好20.5.1和20.4.2WHQL是指软件或驱动程序的版本号。这些版本号通常用于标识软件或驱动程序的更新或修复。在计算机领域中,WHQL代表Windows硬件质量实验室,它是微软公司用来测试和验证硬件和驱动程序的合规性和稳定性的机构。因此,20.5.1和20.4.2WHQL表示这些软件或驱动程序已经通过了微软的测试和验证,可以安全地使用在Windows操作系统中。AMDrx580显卡相对稳定驱动20.5.1和20.4.2WHQL是指软件或驱动程序的版本号。这些版本号通

赛扬g4900和i36100哪个好当涉及到赛扬G4900和I36100这两款处理器时,毫无疑问,I36100的性能更胜一筹。赛扬处理器通常被视为低端处理器,主要用于廉价笔记本电脑。而I3处理器则主要用于高端处理器,其性能非常出色。不论是玩游戏还是观看视频,使用I3处理器都不会出现任何卡顿情况。因此,如果你有可能,尽量选择购买英特尔I系列处理器,特别是用于台式机,这样你就能畅享网络世界的乐趣了。赛扬G4900T性能怎么样从性能方面来看,奔腾G4900T在频率方面表现出色,相比之前的版本,CPU性能


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SublimeText3 Linux新版
SublimeText3 Linux最新版

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),