PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > PHP教程 > 正文

    php生成圆角图片的方法

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:这篇文章主要介绍了php生成圆角图片的方法,涉及php操作图片的技巧,非常具有实用价值,需要的朋友可以参考下本文实例讲述了php生成圆角图片的...
    这篇文章主要介绍了php生成圆角图片的方法,涉及php操作图片的技巧,非常具有实用价值,需要的朋友可以参考下

    本文实例讲述了php生成圆角图片的方法。分享给大家供大家参考。具体如下:

    代码如下:
    1. <?php 
    2. $image_file = $_GET['src']; 
    3. $corner_radius = isset($_GET['radius']) ? $_GET['radius'] : 20; // The default corner radius is set to 20px 
    4. $topleft = (isset($_GET['topleft']) and $_GET['topleft'] == "no") ? false : true; // Top-left rounded corner is shown by default 
    5. $bottomleft = (isset($_GET['bottomleft']) and $_GET['bottomleft'] == "no") ? false : true; // Bottom-left rounded corner is shown by default 
    6. $bottomright = (isset($_GET['bottomright']) and $_GET['bottomright'] == "no") ? false : true; // Bottom-right rounded corner is shown by default 
    7. $topright = (isset($_GET['topright']) and $_GET['topright'] == "no") ? false : true; // Top-right rounded corner is shown by default 
    8. $imagetype=strtolower($_GET['imagetype']); 
    9. $backcolor=$_GET['backcolor']; 
    10. $endsize=$corner_radius
    11. $startsize=$endsize*3-1; 
    12. $arcsize=$startsize*2+1; 
    13. if (($imagetype=='jpeg'or ($imagetype=='jpg')) { 
    14. $image = imagecreatefromjpeg($image_file); 
    15. else { 
    16. if (($imagetype=='GIF'or ($imagetype=='gif')) { 
    17. $image = imagecreatefromgif($image_file); 
    18. else { 
    19. $image = imagecreatefrompng($image_file); 
    20. $size = getimagesize($image_file); 
    21. // Top-left corner 
    22. $background = imagecreatetruecolor($size[0],$size[1]); 
    23. imagecopymerge($background,$image,0,0,0,0,$size[0],$size[1],100); 
    24. $startx=$size[0]*2-1; 
    25. $starty=$size[1]*2-1; 
    26. $im_temp = imagecreatetruecolor($startx,$starty); 
    27. imagecopyresampled($im_temp$background, 0, 0, 0, 0, $startx$starty$size[0], $size[1]); 
    28. $bg = imagecolorallocate($im_temp, hexdec(substr($backcolor,0,2)),hexdec(substr($backcolor,2,2)),hexdec(substr($backcolor,4,2))); 
    29. $fg = imagecolorallocate($im_temp, hexdec(substr($forecolor,0,2)),hexdec(substr($forecolor,2,2)),hexdec(substr($forecolor,4,2))); 
    30. if ($topleft == true) { 
    31. imagearc($im_temp$startsize$startsize$arcsize$arcsize, 180,270,$bg); 
    32. imagefilltoborder($im_temp,0,0,$bg,$bg); 
    33. // Bottom-left corner 
    34. if ($bottomleft == true) { 
    35. imagearc($im_temp,$startsize,$starty-$startsize,$arcsize,$arcsize,90,180,$bg); 
    36. imagefilltoborder($im_temp,0,$starty,$bg,$bg); 
    37. // Bottom-right corner 
    38. if ($bottomright == true) { 
    39. imagearc($im_temp$startx-$startsize$starty-$startsize,$arcsize$arcsize, 0,90,$bg); 
    40. imagefilltoborder($im_temp,$startx,$starty,$bg,$bg); 
    41. // Top-right corner 
    42. if ($topright == true) { 
    43. imagearc($im_temp$startx-$startsize$startsize,$arcsize$arcsize, 270,360,$bg); 
    44. imagefilltoborder($im_temp,$startx,0,$bg,$bg); 
    45. $newimage = imagecreatetruecolor($size[0],$size[1]); 
    46. imagecopyresampled($image,$im_temp,0,0,0,0,$size[0],$size[1],$startx,$starty); 
    47. // Output final image www.bcty365.com 
    48. header("Content-type: image/png"); 
    49. imagepng($image); 
    50. imagedestroy($image); 
    51. imagedestroy($background); 
    52. imagedestroy($im_temp); 
    53. ?> 

     


    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-10-2981-1.html
    相关热词搜索: