找回密码
 注册
【阿里云】2核2G云新老同享 99元/年,续费同价华为云精选云产品特惠做网站就用糖果主机Jtti,新加坡服务器,美国服务器,香港服务器
查看: 451|回复: 3

[PCDOG编程-php]PHP中实现图片的锐化

[复制链接]
发表于 2005 年 10 月 9 日 12:25:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
    //读取图像的类型   //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   for ($y=1; $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 rr, gg, bb;    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);   }    ?>      请输入图片的本地路径或URL:>    size=32>   锐化度数(例:0.6、3.0):   >  
         改了一下,省了一个$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;    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);    }   }     


转自:  PCDOG编程-php
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
发表于 2005 年 10 月 9 日 12:39:39 | 显示全部楼层
【腾讯云】2核2G云服务器新老同享 99元/年,续费同价
[s:16]  [s:16]  [s:16]
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 10 月 9 日 13:20:57 | 显示全部楼层
[s:25]  [s:16]
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

 楼主| 发表于 2005 年 10 月 9 日 12:25:34 | 显示全部楼层

[PCDOG编程-php]PHP中实现图片的锐化

    //读取图像的类型   //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   for ($y=1; $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 rr, gg, bb;    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);   }    ?>      请输入图片的本地路径或URL:>    size=32>   锐化度数(例:0.6、3.0):   >  
         改了一下,省了一个$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;    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);    }   }     


转自:  PCDOG编程-php
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|金光论坛

GMT+8, 2024 年 11 月 20 日 17:26 , Processed in 0.128861 second(s), 24 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表