相思资源网 Design By www.200059.com
<?
//读取图像的类型
//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);
}
}
//读取图像的类型
//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);
}
}
标签:
用PHP实现图象锐化代码
相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com
暂无用PHP实现图象锐化代码的评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。