时间:2016-02-24 21:09 来源: 我爱IT技术网 作者:佚名
欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【非常简单PHP缩略图生成程序源代码】,下面是详细的分享!
非常简单PHP缩略图生成程序源代码
$FILENAME="image_name";
// 生成图片的宽度
$RESIZEWIDTH=400;
// 生成图片的高度
$RESIZEHEIGHT=400;
function ResizeImage($im,$maxwidth,$maxheight,$name){
$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($_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); www~phperz~com
ImageDestroy ($im);
}
}
?>
<img src=http://www.chinaz.com/program/2010/0330/"<? echo($FILENAME.".jpg?reload=".rand(0,999999)); ?>"><br><br>
<form enctype="multipart/form-data" method="post">
<br>
<input type="file" name="image" size="50" value="浏览"><p>
<input type="submit" value="上传图片">
</form>
</body>
</html>
以上所分享的是关于非常简单PHP缩略图生成程序源代码,下面是编辑为你推荐的有价值的用户互动:
相关问题:php 完整图片自动生成缩略图代码
答:ImageMagick没用过,一般直接用内置的GD库,没有发现你说的这么严重的失真问题。 利用GD库创建缩略图的大致思路如下: 依据设定的尺寸创建真彩色画布$im=createtruecolor(120,90); 读取原始文件尺寸,按照原始尺寸的宽度和高度比例,计算出缩略... >>详细
相关问题:PHP如何把上传的照片生成高质量的缩略图?
答:先标记下,稍后上传完整代码 你可以选择是否保留原图 //如果你不想要原图,就把下面两行删掉 图片 >>详细
相关问题:PHP 图片上传生成缩略图
答:这个用 GD 库解决吧! 得到客户上传的图片, 再用GD库引入图片 , 再进行等比例缩小处理 , 就得到缩略图了 . >>详细
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
