首页 / PHP / php生成缩略图的效能
php生成缩略图的效能
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php生成缩略图的效能,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2554字,纯文字阅读大概需要4分钟。
内容图文
![php生成缩略图的效能](/upload/InfoBanner/zyjiaocheng/228/6dba0bb119cf444bad96ec11d59192c1.jpg)
客户自己上传的图片大小不标准,想让传上来的图片统一变成150X113尺寸的。从网上搜到的程序在IE里用正常,到了别的浏览器(如搜狗浏览器等)就不行,这是什么原因?(感觉老是不执行)
代码如下:
session_start();
if (isset($_SESSION['adminname']) && isset($_SESSION['adminpass'])){
//****************************************
//生成缩略图========================================
$myname=date("YmdHis");
$filename="product/min/".$myname; //小图片文件名
$resizewidth=150; // 生成图片的宽度
$resizeheight=113; // 生成图片的高度
function ResizeImage($im,$maxwidth,$maxheight,$name){
$resizewidth = $resizeheight = false;
$width = imagesx($im);
$height = imagesy($im);
if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
if($maxwidth && $width > $maxwidth){
$widthratio = $maxwidth/$width;
$resizewidth=true;
}
if($maxheight && $height > $maxheight){
$heightratio = $maxheight/$height;
$resizeheight=true;
}
if($resizewidth && $resizeheight){
if($widthratio < $heightratio){
$ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif($resizewidth){
$ratio = $widthratio;
}elseif($resizeheight){
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
if(function_exists("imagecopyresampled")){
$newim = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}else{
$newim = imagecreate($newwidth, $newheight);
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
ImageJpeg ($newim,$name . ".jpg");
ImageDestroy ($newim);
}else{
ImageJpeg ($im,$name . ".jpg");
}
}
if(isset($_FILES['image']['size'])){
if($_FILES['image']['type'] == "image/pjpeg"){
$im = imagecreatefromjpeg($_FILES['image']['tmp_name']);
}elseif($_FILES['image']['type'] == "image/x-png"){
$im = imagecreatefrompng($_FILES['image']['tmp_name']);
}elseif($_FILES['image']['type'] == "image/gif"){
$im = imagecreatefromgif($_FILES['image']['tmp_name']);
}
if($im){
if(file_exists("$filename.jpg")){
unlink("$filename.jpg");
}
ResizeImage($im,$resizewidth,$resizeheight,$filename); //生成小图
ImageDestroy ($im);
echo "上传成功,图片文件名是:";
echo $myname.".jpg";
}
}
//****************************************
}else{
echo "";
}
?>
内容总结
以上是互联网集市为您收集整理的php生成缩略图的效能全部内容,希望文章能够帮你解决php生成缩略图的效能所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。