ホームページ  >  記事  >  バックエンド開発  >  PHP での画像の鮮明化_PHP チュートリアル

PHP での画像の鮮明化_PHP チュートリアル

WBOY
WBOYオリジナル
2016-07-21 16:09:46869ブラウズ

<

//画像タイプを読み取る

//1 = GIF、2 = JPG、3 = PNG、4 = SWF、5 = PSD、6 = BMP、7 = TIFF (インテル バイト オーダー)、8 = TIFF(motorola byte order)、9 = JPC、10 = JP2、11 = JPX、12 = JB2、13 = SWC、14 = IFF

function GetImageType($filename) {return (($imginfo=@getimagesize( =null) , &$dst_im, $degree)

$src_x = imagex($src_im);

$src_y = imagey($src_im)

//$dst_im = imagecreate($src_x, $src_y);

//imagecopy($dst_im, $src_im, 0, 0, 0, 0, $src_x, $src_y);

$cnt = 0; $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"])); = 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 = Imagecolorallocate($ dst_im, $r, $g, $b);

$cnt++;

if ($dst_clr==-1) die("$x, $y ($cnt) でカラー割り当て失敗。"); imagesetpixel($dst_im, $x, $y, $dst_clr);

return $dst_im; frompng") ;

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["画像名"]);

$im2 = $ImageFunctions[$ImageType]($_POST["画像名"])

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

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

imagepng($im2); );

imagedestroy($im2);

?>

画像のローカルパスを入力してください。 URL:


;

シャープネス度 (例: 0.6、3.0):

;">

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"]+$);度*($clr2["赤"]-$ clr1["赤"]));

$g = intval($clr2["緑"]+$程度*($clr2["緑"]-$clr1) ["緑"]));

$b = intval($clr2["青"]+$degree*($clr2["青"]-$clr1["青"]));

$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("$x, $y でカラー割り当て失敗) ($cnt).");

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

}

}

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/314463.html技術記事 ? //画像タイプの読み取り//1 = GIF、2 = JPG、3 = PNG、4 = SWF、5 = PSD、6 = BMP、7 = TIFF(インテル バイト オーダー)、8 = TIFF(モトローラ バイト オーダー)、 9 = JPC、10 = JP2、11 = JPX、12 = JB2、...
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。