php生成图片缩略图功能示例
本文实例讲述了php生成图片缩略图功能。分享给大家供大家参考,具体如下:
完整代码如下:
代码如下 | 复制代码 |
<?php /* * Created on 2011-3-18 * * To change the template for this generated file go to * Window - Preferences - PHPeclipse - PHP - Code Templates */ /*构造函数-生成缩略图+水印,参数说明: $srcFile-图片文件名, $dstFile-另存文件名, $markwords-水印文字, $markimage-水印图片, $dstW-图片保存宽度, $dstH-图片保存高度, $rate-图片保存品质*/ makethumb("1.jpg","aa/b.jpg","50","50"); functionmakethumb($srcFile,$dstFile,$dstW,$dstH,$rate= 100,$markwords= null,$markimage= null) { $data=GetImageSize($srcFile); switch($data[2]) { case1: $im= @ImageCreateFromGIF($srcFile); break; case2: $im= @ImageCreateFromJPEG($srcFile); break; case3: $im= @ImageCreateFromPNG($srcFile); break; } if(!$im)returnFalse; $srcW= ImageSX($im); $srcH= ImageSY($im); $dstX= 0; $dstY= 0; if($srcW*$dstH>$srcH*$dstW) { $fdstH=round($srcH*$dstW/$srcW); $dstY=floor(($dstH-$fdstH) / 2); $fdstW=$dstW; }else{ $fdstW=round($srcW*$dstH/$srcH); $dstX=floor(($dstW-$fdstW) / 2); $fdstH=$dstH; } $ni= ImageCreateTrueColor($dstW,$dstH); $dstX= ($dstX< 0) ? 0 :$dstX; $dstY= ($dstX< 0) ? 0 :$dstY; $dstX= ($dstX> ($dstW/ 2)) ?floor($dstW/ 2) :$dstX; $dstY= ($dstY> ($dstH/ 2)) ?floor($dstH/ s) :$dstY; $white= ImageColorAllocate($ni, 255, 255, 255); $black= ImageColorAllocate($ni, 0, 0, 0); imagefilledrectangle($ni, 0, 0,$dstW,$dstH,$white);// 填充背景色 ImageCopyResized($ni,$im,$dstX,$dstY, 0, 0,$fdstW,$fdstH,$srcW,$srcH); if($markwords!= null) { $markwords= iconv("gb2312","UTF-8",$markwords); //转换文字编码 ImageTTFText($ni, 20, 30, 450, 560,$black,"simhei.ttf",$markwords);//写入文字水印 //参数依次为,文字大小|偏转度|横坐标|纵坐标|文字颜色|文字类型|文字内容
}elseif($markimage!= null) { $wimage_data=GetImageSize($markimage); switch($wimage_data[2]) { case1: $wimage= @ImageCreateFromGIF($markimage); break; case2: $wimage= @ImageCreateFromJPEG($markimage); break; case3: $wimage= @ImageCreateFromPNG($markimage); break; } imagecopy($ni,$wimage, 500, 560, 0, 0, 88, 31);//写入图片水印,水印图片大小默认为88*31 imagedestroy($wimage); } ImageJpeg($ni,$dstFile,$rate); ImageJpeg($ni,$srcFile,$rate); imagedestroy($im); imagedestroy($ni); } ?> |
PHP使用在很多用户的生活中是很重要的,那么php怎么获取excel文件数据呢?有些什么获取方法,还不知道的下面我们就一起来看看。
很简单就可以实现,下面为大家简单介绍下
1、下载PHPExcel类,是一个文件夹,还得有一个文件PHPExcel.php,两个在同级目录
require__DIR__ .'./PHPExcel/IOFactory.php'
$PHPReader=new\PHPExcel_Reader_Excel2007();
//判断文件类型
if(!$PHPReader->canRead($filePath)) {
$PHPReader=new\PHPExcel_Reader_Excel5();
if(!$PHPReader->canRead($filePath)) {
echo'no Excel'
returnfalse;
}
}
$PHPExcel=$PHPReader->load($filePath);
/**读取excel文件中的第一个工作表*/
$currentSheet=$PHPExcel->getSheet(0);
/**取得最大的列号*/
$allColumn=$currentSheet->getHighestColumn();
/**取得一共有多少行*/
$allRow=$currentSheet->getHighestRow();
/**从第1行开始输出*/
for($currentRow= 1;$currentRow<=$allRow;$currentRow++) {
/**从第A列开始输出*/
for($currentColumn='A'$currentColumn<=$allColumn;$currentColumn++) {
$val=$currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65,$currentRow)->getValue();
/**ord()将字符转为十进制数*/
$date[$currentRow- 1][] =$val;
}
}
return$date;
Mac系统也是现在使用比较多的系统,今天文章要给大家介绍的是mac系统下怎么安装多个php并自由切换,还不知道具体方法的下面一起来看看。最近工作中遇到一个问题,需要实现在mac系统下安装多个php并实现自由切换,通过查找相关的资料找到了解决的方法,所以想着总结下来,方便大家和自己学习参考,下面话不多说,来看看的介绍吧。
一、安装多版本php
$ brew install php54
$ brew install php70
如果安装报以下错误:
Error: Cannot install homebrew/php/php70 because conflicting formulae are installed.
php54: because different php versions install the same binaries.
Please `brew unlink php54` before continuing.
解决办法有二种:
1、brew unlink php54
2、删除/usr/local/bin,下面有关php的软链接
上面2种方法,目的是一样的。
二、安装切换工具php-version
$ brew install php-version
$ source $(brew --prefix php-version)/php-version.sh
$ php-version
5.4.45
* 7.0.17
$ php-version 5.4.45 //切换到5.4
$ php-version
* 5.4.45
7.0.17
$ echo "source $(brew --prefix php-version)/php-version.sh" >> ~/.bash_profile
代码如下 | 复制代码 |
html文件代码
代码如下 | 复制代码 |
<!-- ajax文件上传开始 --> <scripttype="text/javascript"src="/imageupload/jquery-1.10.2.min.js"></script> <scripttype="text/javascript"src="/imageupload/layer/layer.js"></script> <scripttype="text/javascript"src="/imageupload/ajaxupload.js"></script> <!--ajax文件上传结束--> <!--上传文件按钮列表开始--> <inputid="requesturl"type="hidden"value="{:U('admin/upload/uploadfile')}"/> <inputid="ajaxuploadfile"type="file"onchange="filechange()"/> <inputid="filepathurl"type="hidden"value=""/> <inputtype="button"value="第一张"pathurl="./Uploads/admin/trailer/"class="uploadclass"/> <inputtype="button"value="第二张"pathurl="./Uploads/admin/fdfdfd/"class="uploadclass"/> <inputtype="button"value="第三张"pathurl="./Uploads/admin/cdcdfd/"class="uploadclass"/> <!--上传文件按钮列表结束--> |
php文件代码
代码如下 | 复制代码 |
/** * 文件上传方法 */ publicfunctionuploadfile(){ //单文件上传 $upload=new\Think\Upload();// 实例化上传类 $upload->maxSize = 100000000 ;// 设置附件上传大小 $upload->exts =array('jpg','gif','png','jpeg');// 设置附件上传类型 $url=$_POST['filepathurl']; if(!file_exists($url)){ mkdir($url,0777,true); } $upload->rootPath =$url;// 设置附件上传根目录 // 上传单个文件 $info=$upload->uploadOne($_FILES['postfilename']); if(!$info) { echojson_encode(array('bool'=>false,'error'=>$upload->getError())); }else{ $path=$info['savepath'].$info['savename']; echojson_encode(array('bool'=>true,'path'=>$path)); } } |
相关文章
- 这篇文章主要介绍了C#实现图片放大功能的按照像素放大图像方法,功能非常实用,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了c#生成高清缩略图的二个示例,需要的朋友可以参考下...2020-06-25
- 在本篇文章中小编给各位整理了一篇关于python中翻译功能translate模块实现方法,有需要的朋友们可以参考下。...2020-12-18
- phpmyadmin还有高级功能可能大部份站长不知道吧,今天本文章就来给大家介绍phpMyAdmin 高级功能设置的方法图解,希望文章对大家会有所帮助。 phpMyAdmin 安装后,默认...2016-11-25
- AngularJS 让人爱不释手的八种功能,想知道AngularJS哪八种功能让人喜欢就快点看下本文吧...2016-03-28
- EMUI11值得升级吗?好不好用?下面小编带来EMUI11上手体验,一起来看看手机鸿蒙OS的提前预演...2020-12-08
- 这篇文章主要给大家介绍了关于微信小程序实现导航功能的操作步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-10
- 小爱同学5.0即将发布,据已知报道小爱同学5.0将新增机型,跟着小编一起来看看吧,顺便了解下即将都有哪些新功能面市吧...2020-12-08
- 这款批量生成缩略图代码可以生成指定大小的小图哦,并且支持文件批量上传。 这款教程会用到php文件 view.php config.php funs.php index.php 功能: -------...2016-11-25
- 这篇文章主要介绍了C#实现为一张大尺寸图片创建缩略图的方法,涉及C#创建缩略图的相关图片操作技巧,需要的朋友可以参考下...2020-06-25
- 这篇文章主要为大家分享了一份很全面的JavaScript常用功能汇总集合,一些常用的额JS 对象、基本数据结构、功能函数等,感兴趣的小伙伴们可以参考一下...2016-01-24
- if( isset($_FILES['upImg']) ) { if( $userGroup[$loginArr['group']]['upload'] == 0 ) { echo '{"error":"您所在的用户组无权上传图片!"}'; } else...2016-11-25
.net生成缩略图及水印图片时出现GDI+中发生一般性错误解决方法
这篇文章主要介绍了.net生成缩略图及水印图片时出现GDI+中发生一般性错误解决方法 ,需要的朋友可以参考下...2021-09-22Night Shift是什么意思 Night Shift有什么功能及作用?
Night Shift是IOS9.3正式版系统新增加的功能之一,很多伙伴们都不清楚Night Shift是什么意思?以及Night Shift有什么用途?对此,本文小编就为大家详细介绍Night Shift的含义及作用...2016-07-04- 把下面的文件保存为index.php <? /* MailX Managment System 0.8 Beta */ header("Content-type:image/png"); $mailaddress=$_GET['mailname']; $mailaddres...2016-11-25
- 这篇文章主要给大家介绍了在CentOS系统下编译安装nginx及配置缩略图插件的方法教程,文中给出了详细的安装步骤,对大家具有一定的参考价值,有需要的朋友们下面来一起看看吧。...2017-07-06
- <?php include_once("mime.inc"); $mm = new MIME(); $to = "customer@263.net"; $subject = $mm->encode("商城","gb2312"); // 编码 $msg = "注册会员成功<br>"; $m...2016-11-25
php基于ob_start(ob_gzhandler)实现网页压缩功能的方法
小编推荐的这篇文章介绍了php基于ob_start(ob_gzhandler)实现网页压缩功能的方法,非常实用,有兴趣的同学可以看看。 PHP生成网页后传送给浏览器显示 ,页面的打开速度...2017-07-06- 小米在最新的MIUI8中正式加入了录屏功能,用户再也不需要ROOT手机,然后借助“录屏大师”等APP来录屏了,借助系统自带的录屏功能即可轻松录制屏幕。那么,MIUI8录屏功能录屏功能在哪?MIUI8录屏功能怎么使用?本文将提供MIUI小米手机录屏使用方法图文教程供大家了解...2017-07-06
- 这篇文章主要介绍了thinkPHP商城公告功能开发问题,结合实例形式分析了基于thinkPHP实现商城公告功能所涉及的ajax交互及数据库操作相关技巧,需要的朋友可以参考下...2016-12-02