在PHP中也可实现图片的锐化操作,效果类似于Photoshop中的效果,这个PHP图像锐化处理函数结果发现这个非常不错,现在分享给大家了。
php图像锐化处理函数<?php
function GDThrowError($message)
{
$font = 2;
$errimg = imagecreate((imagefontwidth($font) * strlen($message)) + 20, imagefontheight($font) + 10);
$bg = imagecolorallocate($errimg, 255, 255, 255);
$textcol = imagecolorallocate($errimg, 0, 0, 0);
imagestring($errimg, 2, 10, 5, $message, $textcol);
header('Content-type: image/jpeg');
imagejpeg($errimg);
imagedestroy($errimg);
}
function GDMakeJpegLookLikeCrap($target)
{
if (($dims = @getimagesize($target)) === false || $dims['mime'] != 'image/jpeg')
{
GDThrowError('The file you specified couldn\'t be found or is not a valid jpeg image. Make sure you spelled it correctly and provided the correct path.');
return(false);
}
$image = imagecreatefromjpeg($target);
$spnMatrix = array( array(-1,-1,-1,),
array(-1,16,-1,),
array(-1,-1,-1));
$divisor = 8;
$offset = 0;
imageconvolution($image, $spnMatrix, $divisor, $offset);
header('Content-type: image/jpeg');
imagejpeg($image, null, 100);
imagedestroy($image);
}
$s_image = (isset($_GET['image'])) ? $_GET['image'] : null;
if (preg_match('/\.(jpg|jpeg)$/i', $s_image))
{
GDMakeJpegLookLikeCrap($s_image);
}
else
{
GDThrowError('Please specify a jpeg file to sharpen in the form: ' . $_SERVER['PHP_SELF'] . '?image=filename.jpg');
}
?>