| 域名空间 下载中心 社区论坛 信息公告 my小屋 |
![]() |
联系我们 设为首页 加入收藏 |
|
首页 | 新闻资讯 | 编程开发 | 网页设计 | 图形图象 | 网络媒体 | 网站模板 | 数 据 库 | 投稿 论坛 | 操作系统 | 系统优化 | 网络安全 | 黑客技术 | 硬件学堂 | 硬件报价 | 服 务 器 | 地图 专题 | 应用软件 | 聊天通讯 | q q 专栏 | 建站经验 | 在线工具 | 站长club | 注 册 表 | 旧版 社会 | 游戏娱乐 | 设计欣赏 | 疑难解答 | 社区论坛 | 韩国素材 | 素材图库 | 广告服务 | 服务 |
| 新版上线![旧版] | |||||
注:打开慢时请稍等
如何实现任意支持格式的图片的缩放? <<========>> 谁来帮我完成1个图片缩放函数?http://www.iyit.net 日期:2006-10-6 15:37:15 来源:iyit.net收集 点击: |
偶在收藏的。看看合合适你 <? //测试用。 $filename="filename"; // 生成图片的宽度 $resizewidth=200; // 生成图片的高度 $resizeheight=150; 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"); //imagedestroy ($newim); } } echo $_files['image']['type']."<br>"; echo $_files['image']['size'],"<br>"; echo $_files['image']['tmp_name'],"<br>"; echo $_files['image']['name']."<br>"; 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); imagedestroy ($im); //删除 } } ?> <img src="<? echo $filename.'.jpg?reload='.rand(0,999999); ?>"><br/><br/> <img src="<? echo $filename.'.jpg?rd='.rand(0,999999); ?>"><br/><br/> <form enctype="multipart/form-data" method="post"> <br/> <input type="file" name="image" size="50" ><p> <input type="submit" value="上传图片"> </form> </body> </html> 好晚了,想不到搞一两个页面搞了那么晚。睡觉去...... 编辑:黑鹰 [发送给好友] [打印本页] [关闭窗口] [返回顶部] 上一篇:关于多层目录中文件嵌套引用的问题。。。。。。。。。。。。。。。。。 下一篇:在线等!请进来看~~!先拜谢!! 转载请注明来源:www.iyit.net 特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。 |
| 相关文章 | ||||
| 设置首 页 - 版权声明 - 广告服务 - 关于我们 - 联系我们 - 友情连接 |
| |||||||