首页 > 后端开发 > php教程 > php生成圆角图片代码

php生成圆角图片代码

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

圆角, php


相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板