[PHP实例] php生成圆角图片代码

来源:互联网 发布:网络的利与弊作文600 编辑:程序博客网 时间:2024/05/22 15:18
  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 defaulthttp://m.ynmxzx.com/ybzx/2016/0614/1023.html
  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. }http://m.ynmxzx.com/ybzx/2016/0614/1024.html
  21. }
  22. $size = getimagesize($image_file);
  23. // Top-left corner
  24. $background = imagecreatetruecolor($size[0],$size[1]);
  25. imagecopymerge($background, $image, 0, 0, 0, 0, $size[0], $size[1], 100);
  26. $startx=$size[0]*2-1;
  27. $starty=$size[1]*2-1;
  28. $im_temp = imagecreatetruecolor($startx,$starty);
  29. imagecopyresampled($im_temp, $background, 0, 0, 0, 0, $startx, $starty, $size[0], $size[1]);
  30. $bg = imagecolorallocate($im_temp, hexdec(substr($backcolor,0,2)),hexdec(substr($backcolor,2,2)),hexdec(substr($backcolor,4,2)));
  31. $fg = imagecolorallocate($im_temp, hexdec(substr($forecolor,0,2)),hexdec(substr($forecolor,2,2)),hexdec(substr($forecolor,4,2)));
  32. http://m.ynmxzx.com/ybzx/2016/0614/1025.html
  33. if ($topleft == true) {
  34. imagearc($im_temp, $startsize, $startsize, $arcsize, $arcsize, 180,270,$bg);
  35. imagefilltoborder($im_temp,0,0,$bg,$bg);
  36. }
  37. // Bottom-left corner
  38. if ($bottomleft == true) {
  39. imagearc($im_temp, $startsize, $starty-$startsize,$arcsize, $arcsize, 90,180,$bg);
  40. imagefilltoborder($im_temp,0,$starty,$bg,$bg);
  41. }
  42. http://m.ynmxzx.com/ybzx/2016/0614/1026.html
  43. // Bottom-right corner
  44. if ($bottomright == true) {
  45. imagearc($im_temp, $startx-$startsize, $starty-$startsize,$arcsize, $arcsize, 0,90,$bg);
  46. imagefilltoborder($im_temp,$startx,$starty,$bg,$bg);
  47. }
  48. // Top-right corner
  49. if ($topright == true) {
  50. imagearc($im_temp, $startx-$startsize, $startsize,$arcsize, $arcsize, 270,360,$bg);
  51. imagefilltoborder($im_temp,$startx,0,$bg,$bg);
  52. }
  53. $newimage = imagecreatetruecolor($size[0],$size[1]);
  54. imagecopyresampled($image, $im_temp, 0, 0, 0, 0, $size[0],$size[1],$startx, $starty);
  55. http://m.ynmxzx.com/ybzx/2016/0614/1027.html
  56. // Output final image
  57. header("Content-type: image/png");
  58. imagepng($image);
  59. imagedestroy($image);
  60. imagedestroy($background);
  61. imagedestroy($im_temp);
  62. ?>m.ynmxzx.com
0 0
原创粉丝点击