php 等比例缩小宽高
来源:互联网 发布:数据库服务器地址 编辑:程序博客网 时间:2024/05/16 05:31
$file1 = "aa.jpg";
$maxWidth = 830;
function resizeImage($im,$maxwidth,$maxheight,$name,$filetype)
{
$pic_width = imagesx($im);
$pic_height = imagesy($im);
if(($maxwidth && $pic_width > $maxwidth) || ($maxheight && $pic_height > $maxheight))
{
if($maxwidth && $pic_width>$maxwidth)
{
$widthratio = $maxwidth/$pic_width;
$resizewidth_tag = true;
}
if($maxheight && $pic_height>$maxheight)
{
$heightratio = $maxheight/$pic_height;
$resizeheight_tag = true;
}
/* if($resizewidth_tag && $resizeheight_tag)
{
if($widthratio<$heightratio)
$ratio = $widthratio;
else
$ratio = $heightratio;
}*/
if($resizewidth_tag )
$ratio = $widthratio;
/* if($resizeheight_tag && !$resizewidth_tag)
$ratio = $heightratio;*/
$newwidth = $pic_width * $ratio;
$newheight = $pic_height * $ratio;
if(function_exists("imagecopyresampled"))
{
$newim = imagecreatetruecolor($newwidth,$newheight);//PHP系统函数
imagecopyresampled($newim,$im,0,0,0,0,$newwidth,$newheight,$pic_width,$pic_height);//PHP系统函数
}
else
{
$newim = imagecreate($newwidth,$newheight);
imagecopyresized($newim,$im,0,0,0,0,$newwidth,$newheight,$pic_width,$pic_height);
}
$name = $name.$filetype;
imagejpeg($newim,$name);
imagedestroy($newim);
}
else
{
$name = $name.$filetype;
imagejpeg($im,$name);
}
}
//使用方法:
$im=imagecreatefromjpeg("aa.jpg");//参数是图片的存方路径
$maxwidth="830";//设置图片的最大宽度
$maxheight="1000";//设置图片的最大高度
$name="123";//图片的名称,随便取吧
$filetype=".jpg";//图片类型
resizeImage($im,$maxwidth,$maxheight,$name,$filetype);//调用上面的函数
$maxWidth = 830;
function resizeImage($im,$maxwidth,$maxheight,$name,$filetype)
{
$pic_width = imagesx($im);
$pic_height = imagesy($im);
if(($maxwidth && $pic_width > $maxwidth) || ($maxheight && $pic_height > $maxheight))
{
if($maxwidth && $pic_width>$maxwidth)
{
$widthratio = $maxwidth/$pic_width;
$resizewidth_tag = true;
}
if($maxheight && $pic_height>$maxheight)
{
$heightratio = $maxheight/$pic_height;
$resizeheight_tag = true;
}
/* if($resizewidth_tag && $resizeheight_tag)
{
if($widthratio<$heightratio)
$ratio = $widthratio;
else
$ratio = $heightratio;
}*/
if($resizewidth_tag )
$ratio = $widthratio;
/* if($resizeheight_tag && !$resizewidth_tag)
$ratio = $heightratio;*/
$newwidth = $pic_width * $ratio;
$newheight = $pic_height * $ratio;
if(function_exists("imagecopyresampled"))
{
$newim = imagecreatetruecolor($newwidth,$newheight);//PHP系统函数
imagecopyresampled($newim,$im,0,0,0,0,$newwidth,$newheight,$pic_width,$pic_height);//PHP系统函数
}
else
{
$newim = imagecreate($newwidth,$newheight);
imagecopyresized($newim,$im,0,0,0,0,$newwidth,$newheight,$pic_width,$pic_height);
}
$name = $name.$filetype;
imagejpeg($newim,$name);
imagedestroy($newim);
}
else
{
$name = $name.$filetype;
imagejpeg($im,$name);
}
}
//使用方法:
$im=imagecreatefromjpeg("aa.jpg");//参数是图片的存方路径
$maxwidth="830";//设置图片的最大宽度
$maxheight="1000";//设置图片的最大高度
$name="123";//图片的名称,随便取吧
$filetype=".jpg";//图片类型
resizeImage($im,$maxwidth,$maxheight,$name,$filetype);//调用上面的函数
0 0
- php 等比例缩小宽高
- //等比例缩小图片
- 图片等比例缩小
- ImageView等比例缩小
- bitmap等比例缩小
- PHP等比例缩放图片(最大宽或高)
- 利用PHP实现图片等比例放大和缩小
- 判断图片等比例缩小
- iphone 图片等比例缩小
- JS等比例缩小图片尺寸
- 设置图片等比例缩小
- 图像等比例缩小【OpenCV】
- 手机网站等比例缩小
- 控制图片比例、等比例控制图片最大宽高。
- 等比例宽高的ImageView
- CSS强制等比例缩小图片
- 对付IE6.0 等比例缩小img
- Node.js等比例放倒缩小图片
- 一大波64位手机处理器来袭
- 一分析建模题Amazon.com - Employee Access Challenge
- Android开发学习笔记:浅谈WebView
- 新GRE数学四大复习方法
- 大量的QT控件及示例发放
- php 等比例缩小宽高
- xUtils如何通过注解对FindViewById进行封装
- H.264 Profile、Level、Encoder三张简图
- 在 Mac 下用 Homebrew 安装 MySQL
- 优秀员工是这样离职的,你看
- Guava ---- Range范围过滤
- PELCO-D与PELCO-P协议介绍
- Hibernate懒加载
- 新生管理系统,加入了数据库后永久保存(只是学生的增删改查方法)