微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php图像锐化处理函数

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'); 
} 
?>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐