首頁  >  文章  >  後端開發  >  PHP中實作圖片的銳利化_PHP教程

PHP中實作圖片的銳利化_PHP教程

WBOY
WBOY原創
2016-07-21 16:09:46906瀏覽

  

  //讀取影像的類型

  //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 Sharp(&$src_im, &$dst_im, $degree)

  >『 ($src_im);

   $src_y = imagesy($src_im);

   //$dst_im = imagecreate($src_, $ss>); $dst_im, $src_im, 0, 0, 0, 0, $src_x, $src_y);

   $cnt = 0;

   for ($x=1; ; $x )

   for ($y=1; $y

   {

   $src_clr. src_im, $x-1, $y-1));

   $src_clr2 = imagecolorsforindex($src_im, imagecolorat($src_im, $x, $y));

   $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
";

   if (($dst_clr=imagecolorexact($dst_im, $r, $g, $b))==-1)

   $dst_clr = $dcolor_cl $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);

   }

   }

> >  }   

  $ImageFunctions = array("imagecreatefromwbmp", "imagecreatefromgif", "imagecreatefromjpeg", "image); "ImageName"]))

  { 

   set_time_limit(10*60);

   if (($ImageType=GetImageType=$mage)

   die("指定文件不存在或不是有效的圖片或不支援類型! ");

   if ($ImageType==6) $ImageType = 0;

   if ($ImageType>3) die("不支援的圖片類型!");

   $im1 = $ImageFunctions[$ImageType]($_POST["ImageName"]);

   $im2 = $ImageFunctions[$ImageType]($POST[Imim2 = $ImageFunctions[$ImageType]($POST"ImageName");

   //print_r(imagecolorsforindex($im, imagecolorat($im, 10, 10)));

   Sharp($im1, $im2, $_POST["Degree"]);

   header("Content-type: image/png");

   imagepng($im2);

   imagedestro2);

   imagedestro2);

 〜 imagedestroy($imagedestroy($image); );

  } 

  ?>

  

請輸入圖片的圖片本地路徑或URL:

  " size=32>

  銳利化度數(例:0.6、3.0):

  ">

  

  

 

   改了一下,省了一個$im:  

   function Sharp2(&$im, $degree)

  {

   for $cnt> for $cnt = 0 0; $x--)

   for ($y=imagesy($im)-1; $y>0; $y--)

   {

   $clr1 = imagecolorsforindex($im, imagecolorat($im, $x-1, $y-1));

 〔22index = color$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 ;

   $cnt ;    imagesetpixel($im, $x, $y, $new_clr);

   }

  }   

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314463.htmlTechArticle? //讀取影像的類型//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,...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn