欢迎光临
我们一直在努力

PHP中实现图片的锐化-PHP教程,图像处理

建站超值云服务器,限时71元/月

<?

//读取图像的类型

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

{

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » PHP中实现图片的锐化-PHP教程,图像处理
分享到: 更多 (0)

相关推荐

  • 暂无文章