欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php生成圆角图片代码

程序员文章站 2022-06-10 23:06:00
...
  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