通行证: 用户 密码 域名空间  下载中心 社区论坛 信息公告 my小屋
联系我们
设为首页
加入收藏

 

qq,asp,php,jsp,xml,sql,.net,编程 程序 网页图象 建站经验 私服
首页 | 新闻资讯 | 编程开发 | 网页设计 | 图形图象 | 网络媒体 | 网站模板 | 数 据 库 | 投稿
论坛 | 操作系统 | 系统优化 | 网络安全 | 黑客技术 | 硬件学堂 | 硬件报价 | 服 务 器 | 地图
专题 | 应用软件 | 聊天通讯 | q q 专栏 | 建站经验 | 在线工具 | 站长club | 注 册 表 | 旧版
社会 | 游戏娱乐 | 设计欣赏 | 疑难解答 | 社区论坛 | 韩国素材 | 素材图库 | 广告服务 | 服务
当前位置:首页>>在线服务>>疑难解答>>正文 新版上线![旧版]
注:打开慢时请稍等

php中如何实现图片的锐化?

http://www.iyit.net  日期:2006-10-6 15:36:14  来源:iyit.net收集  点击:
参加讨论
如题  
---------------------------------------------------------------  
可以,就是太太太...慢了,而且对gif支持不太好。下面是代码:  
 
<?  
//读取图像的类型  
//1  =  gif,  2  =  jpg,  3  =  png,  4  =  swf,  5  =  psd,  6  =  bmp,  7  =  tiff(intel  byte  order),  8  =  tiff(motorola  byte  order),  9  =  jpc,  10  =  jp2,  11  =  jpx,  12  =  jb2,  13  =  swc,  14  =  iff  
function  getimagetype($filename)  {return  (($imginfo=@getimagesize($filename))!=null  ?  $imginfo[2]  :  null);}  
 
//图像锐化  
//$scr_im:图像资源句柄,$degree:锐化度数  
function  sharp(&$src_im,  &$dst_im,  $degree)  
{  
       $src_x  =  imagesx($src_im);  
       $src_y  =  imagesy($src_im);  
       //$dst_im  =  imagecreate($src_x,  $src_y);  
       //imagecopy($dst_im,  $src_im,  0,  0,  0,  0,  $src_x,  $src_y);  
       $cnt  =  0;  
       for  ($x=1;  $x<$src_x;  $x++)  
               for  ($y=1;  $y<$src_y;  $y++)  
               {  
                       $src_clr1  =  imagecolorsforindex($src_im,  imagecolorat($src_im,  $x-1,  $y-1));  
                       $src_clr2  =  imagecolorsforindex($src_im,  imagecolorat($src_im,  $x,  $y));  
                       $r  =  intval($src_clr2["red"]+$degree*($src_clr2["red"]-$src_clr1["red"]));  
                       $g  =  intval($src_clr2["green"]+$degree*($src_clr2["green"]-$src_clr1["green"]));  
                       $b  =  intval($src_clr2["blue"]+$degree*($src_clr2["blue"]-$src_clr1["blue"]));  
                       $r  =  min(255,  max($r,  0));  
                       $g  =  min(255,  max($g,  0));  
                       $b  =  min(255,  max($b,  0));  
                       //echo  "r:$r,  g:$g,  b:$b<br/>";  
                       if  (($dst_clr=imagecolorexact($dst_im,  $r,  $g,  $b))==-1)  
                               $dst_clr  =  imagecolorallocate($dst_im,  $r,  $g,  $b);  
                       $cnt++;  
                       if  ($dst_clr==-1)  die("color  allocate  faile  at  $x,  $y  ($cnt).");  
                       imagesetpixel($dst_im,  $x,  $y,  $dst_clr);  
               }  
       return  $dst_im;  
}  
 
$imagefunctions  =  array("imagecreatefromwbmp",  "imagecreatefromgif",  "imagecreatefromjpeg",  "imagecreatefrompng");  
 
if  (!empty($_post["imagename"]))  
{  
       set_time_limit(10*60);  
       if  (($imagetype=getimagetype($_post["imagename"]))==false)  
               die("指定文件不存在或不是有效的图片或不支持类型!");  
       if  ($imagetype==6)  $imagetype  =  0;  
       if  ($imagetype>3)  die("不支持的图片类型!");  
       $im1  =  $imagefunctions[$imagetype]($_post["imagename"]);  
       $im2  =  $imagefunctions[$imagetype]($_post["imagename"]);  
       //print_r(imagecolorsforindex($im,  imagecolorat($im,  10,  10)));  
       sharp($im1,  $im2,  $_post["degree"]);  
       header("content-type:  image/png");  
       imagepng($im2);  
       imagedestroy($im1);  
       imagedestroy($im2);  
}  
 
?>  
<form  name="formname"  action=""  method="post">  
请输入图片的本地路径或url:<br/>  
<input  name="imagename"  type="text"  value="<?=$_post["imagename"]?>"  size=32><br/>  
锐化度数(例:0.6、3.0):<br/>  
<input  name="degree"  type="text"  value="<?=$_post["degree"]?>"><br/>  
<input  type="submit"  value="提交">  
</form>  
 
---------------------------------------------------------------  
 
改了一下,省了一个$im:  
function  sharp2(&$im,  $degree)  
{  
       $cnt  =  0;  
       for  ($x=imagesx($im)-1;  $x>0;  $x--)  
               for  ($y=imagesy($im)-1;  $y>0;  $y--)  
               {  
                       $clr1  =  imagecolorsforindex($im,  imagecolorat($im,  $x-1,  $y-1));  
                       $clr2  =  imagecolorsforindex($im,  imagecolorat($im,  $x,  $y));  
                       $r  =  intval($clr2["red"]+$degree*($clr2["red"]-$clr1["red"]));  
                       $g  =  intval($clr2["green"]+$degree*($clr2["green"]-$clr1["green"]));  
                       $b  =  intval($clr2["blue"]+$degree*($clr2["blue"]-$clr1["blue"]));  
                       $r  =  min(255,  max($r,  0));  
                       $g  =  min(255,  max($g,  0));  
                       $b  =  min(255,  max($b,  0));  
                       //echo  "r:$r,  g:$g,  b:$b<br>";  
                       if  (($new_clr=imagecolorexact($im,  $r,  $g,  $b))==-1)  
                               $new_clr  =  imagecolorallocate($im,  $r,  $g,  $b);  
                       $cnt++;  
                       if  ($new_clr==-1)  die("color  allocate  faile  at  $x,  $y  ($cnt).");  
                       imagesetpixel($im,  $x,  $y,  $new_clr);  
               }  
}  


编辑:黑鹰 [发送给好友] [打印本页] [关闭窗口] [返回顶部]
上一篇:如何再mysql中存储数组?
下一篇:如何制作在线人员统计
转载请注明来源:www.iyit.net
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。

 相关文章
php和asp上传漏洞探究 php作wap开发时遇到的问题  我在windows  xp上安装apache2.044+php
apache+php,怎样打开session支持?? 在linux中怎么配置pdflib和php  高分! 怎么样同时解释.php和.php3的文件呀,急
php 4.1.0 及以后版本使用post变量的接 apache2-win32+php的成功安装方法 我只是想在本地机上学习php ,还要安装
装了php。运行时出现在以下提示 php在win2003上面怎样安装? php 在linux 下如何開啟ftp功能
如何屏蔽掉 phpinfo() php.ini中文版 请问怎样降低php的警告等级?
一个打击了我学习php热情的问题:怎么样 php初学者的入门问题 运行php程序会出现乱码是怎么回事?zen
如何让php拥有root的权限? 为什么php中的函数mail()不能发送邮件 成功地在linux/unix下安装apache+php+o
在win2k下如何安装apache、mysql、php? 请问高手:iis5.0+php4.0安装问题 php session变量在下一页不能读取值的问
最新更新 热点排行 推荐新闻
我在windows  xp上安装apache2.044+ph
apache+php,怎样打开session支持??
在linux中怎么配置pdflib和php  高分!
怎么样同时解释.php和.php3的文件呀,
php 4.1.0 及以后版本使用post变量的接
我的qq被盗走的原因分析
webqq好玩不?大鸟带你一起体验
奇奇怪怪的qq密技十五招
qq被盗到出售过程详解
微软winxp sp3再次跳票 推至08年发布
google苹果合作浏览器 防恶意网站
微软操作系统实现开源?
网管应当如何管理windows操作系统?
让windows xp系统锁定期间拒绝关机
windowsvista中文版11月30日正式发布
我在windows  xp上安装apache2.044+ph
php 在linux 下如何開啟ftp功能
apache2-win32+php的成功安装方法
怎么删除mysql???
apache+php,怎样打开session支持??
合并vcd片断、快速删除文件夹--dos命令
dos教程 dos命令基础应用
破解qq密码如此简单 
低格、分区、高格的应对--dos命令应用
一劳永逸--批处理命令(一)
qq2006 beta3隆重发布 实用功能一一奉
美国微软总部相中重庆15岁网络奇才(图
qq号码激活的常见问题及案例分析 
sql server安装文件挂起错误解决办法
三分钟让你的系统变处女:acronis tru
exeplorer.exe错误的问题的总结、解决
我的qq被盗走的原因分析
webqq好玩不?大鸟带你一起体验
奇奇怪怪的qq密技十五招
qq被盗到出售过程详解
google苹果合作浏览器 防恶意网站
网管应当如何管理windows操作系统?
让windows xp系统锁定期间拒绝关机
windowsvista中文版11月30日正式发布
google优化网站管理员指导方针
hilltop算法- 探索google排名新算法

设置首 页 - 版权声明 - 广告服务 - 关于我们 - 联系我们 - 友情连接
copyrights © 2004-2006 iyit.net all rights reserved.
网站合作、广告联系qq:147007642、466949678
易特网络技术 点击这里给我发消息