兼容性比较好的PHP生成缩略图的代码
2015-01-24信息快讯网
function ImageResize($srcFile,$toW,$toH,$toFile="")
{
if($toFile==""){ $toFile = $srcFile; }
$info = "";
$data = GetImageSize($srcFile,$info);
switch ($data[2])
{
case 1:
if(!function_exists("imagecreatefromgif")){
echo "你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!<a href='javascript:go(-1);'>返回</a>";
exit();
}
$im = ImageCreateFromGIF($srcFile);
break;
case 2:
if(!function_exists("imagecreatefromjpeg")){
echo "你的GD库不能使用jpeg格式的图片,请使用其它格式的图片!<a href='javascript:go(-1);'>返回</a>";
exit();
}
$im = ImageCreateFromJpeg($srcFile);
break;
case 3:
$im = ImageCreateFromPNG($srcFile);
break;
}
$srcW=ImageSX($im);
$srcH=ImageSY($im);
$toWH=$toW/$toH;
$srcWH=$srcW/$srcH;
if($toWH<=$srcWH){
$ftoW=$toW;
$ftoH=$ftoW*($srcH/$srcW);
}
else{
$ftoH=$toH;
$ftoW=$ftoH*($srcW/$srcH);
}
if($srcW>$toW||$srcH>$toH)
{
if(function_exists("imagecreatetruecolor")){
@$ni = ImageCreateTrueColor($ftoW,$ftoH);
if($ni) ImageCopyResampled($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH);
else{
$ni=ImageCreate($ftoW,$ftoH);
ImageCopyResized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH);
}
}else{
$ni=ImageCreate($ftoW,$ftoH);
ImageCopyResized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH);
}
if(function_exists('imagejpeg')) ImageJpeg($ni,$toFile);
else ImagePNG($ni,$toFile);
ImageDestroy($ni);
}
ImageDestroy($im);
}
DOM XPATH获取img src值的query
php提示Call-time pass-by-reference has been deprecated in的解决方法[已测]
PHP __autoload()方法真的影响性能吗?
simplehtmldom Doc api帮助文档
Notice: Trying to get property of non-object problem(PHP)解决办法
MySQL时间字段究竟使用INT还是DateTime的说明
修改PHP的memory_limit限制的方法分享
php _autoload自动加载类与机制分析
PHP __autoload函数(自动载入类文件)的使用方法
PHP函数spl_autoload_register()用法和__autoload()介绍
fgetcvs在linux的问题
Trying to clone an uncloneable object of class Imagic的解决方法
Uncaught exception com_exception with message Failed to create COM object
比file_get_contents稳定的curl_get_contents分享
php删除页面记录 同时刷新页面 删除条件用GET方式获得
php 变量未定义等错误的解决方法
php的日期处理函数及uchome的function_coomon中日期处理函数的研究
php simplexmlElement操作xml的命名空间实现代码
PHP中simplexml_load_string函数使用说明
Wordpress 相册插件 NextGEN-Gallery 添加目录将中文转为拼音的解决办法
PHP的autoload自动加载机制使用说明
Notice: Undefined index: page in E:\PHP\test.php on line 14
php运行出现Call to undefined function curl_init()的解决方法
PHP合并数组+与array_merge的区别分析
PHP中的integer类型使用分析
php 模拟POST|GET操作实现代码
php set_magic_quotes_runtime() 函数过时解决方法
php trim 去除空字符的定义与语法介绍
php set_time_limit(0) 设置程序执行时间的函数
php 提速工具eAccelerator 配置参数详解
在Windows下编译适用于PHP 5.2.12及5.2.13的eAccelerator.dll(附下载)
Fatal error: Call to undefined function curl_init()解决方法