梦想飞翔 - 2006
记录生活,记录点滴~
首页
生活点滴
影音娱乐
游戏生活
学习相关
标签
留言本
搜索
Oct
16
发一个php无组件生成缩略图函数
学习
网上找来的,发现不错,可以用.
如下:
/*************************************************************************** * 作用:缩略图. * 应用: include('miniature.php'); $vres = miniature('源图_name', '缩图_name',缩图宽,缩图高,维持比例); echo $vres; ***************************************************************************/ function miniature($big_image_name, $new_name, $max_width = 400, $max_height = 400, $resize = 1) { if($temp_img_type = @getimagesize($big_image_name)) {eregi('/([a-z]+)$', $temp_img_type[mime], $tpn); $img_type = $tpn[1];} else {eregi('.([a-z]+)$', $big_image_name, $tpn); $img_type = $tpn[1];} $all_type = array( "jpg" => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg" , "exn"=>".jpg"), "gif" => array("create"=>"ImageCreateFromGIF" , "output"=>"imagegif" , "exn"=>".gif"), "jpeg" => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg" , "exn"=>".jpg"), "png" => array("create"=>"imagecreatefrompng" , "output"=>"imagepng" , "exn"=>".png"), "wbmp" => array("create"=>"imagecreatefromwbmp", "output"=>"image2wbmp" , "exn"=>".wbmp") ); $func_create = $all_type[$img_type]['create']; if(empty($func_create) or !function_exists($func_create)) return false; $func_output = $all_type[$img_type]['output']; //$func_exname = $all_type[$img_type]['exn']; $big_image = $func_create($big_image_name); $big_width = imagesx($big_image); $big_height = imagesy($big_image); if($big_width <= $max_width and $big_height <= $max_height) { $func_output($big_image, $new_name.$func_exname); return true; } $ratiow = $max_width / $big_width; $ratioh = $max_height / $big_height; if($resize == 1) { if($big_width >= $max_width and $big_height >= $max_height) { if($big_width > $big_height) { $tempx = $max_width / $ratioh; $tempy = $big_height; $srcX = ($big_width - $tempx) / 2; $srcY = 0; } else { $tempy = $max_height / $ratiow; $tempx = $big_width; $srcY = ($big_height - $tempy) / 2; $srcX = 0; } } else { if($big_width > $big_height) { $tempx = $max_width; $tempy = $big_height; $srcX = ($big_width - $tempx) / 2; $srcY = 0; } else { $tempy = $max_height; $tempx = $big_width; $srcY = ($big_height - $tempy) / 2; $srcX = 0; } } } else { $srcX = 0; $srcY = 0; $tempx = $big_width; $tempy = $big_height; } $new_width = ($ratiow > 1) ? $big_width : $max_width; $new_height = ($ratioh > 1) ? $big_height : $max_height; if(function_exists("imagecopyresampled")) { $temp_image = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($temp_image, $big_image, 0, 0, $srcX, $srcY, $new_width, $new_height, $tempx, $tempy); } else { $temp_image = imagecreate($new_width, $new_height); imagecopyresized($temp_image, $big_image, 0, 0, $srcX, $srcY, $new_width, $new_height, $tempx, $tempy); } $func_output($temp_image, $new_name.$func_exname); ImageDestroy($big_image); ImageDestroy($temp_image); return true; }
tags:
to "发一个php无组件生成缩略图函数"
Leave a Reply
名称(*)
邮箱
网站链接
验证(*)
正文(*)(留言最长字数:1000)
记住我,下次回复时不用重新输入个人信息
网站分类
最新评论及回复
文章归档
Meta
Admin
Entries (RSS)
Comments (RSS)
Z-Blog
最新评论及回复