中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > 综合其它
PHP中实现图片的锐化
作者:佚名 时间:2007-09-13 16:36 出处:互连网 责编:月夜寒箫
              摘要:PHP中实现图片的锐化

没错,PHP也可以实现图片的锐化、模糊、浮雕等操作。因为PHP作为网页脚本特长不在此,但在对效率要求不高、又不想使用CGI的情况下,让我们来看看该怎样做。

下面内容已经被收录在CSDN中PHP的FAQ里:http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=188506



<? 

//读取图像的类型 

//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"])) 

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有