图像上的圆角

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了图像上的圆角相关的知识,希望对你有一定的参考价值。

  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.  
  14. if (($imagetype=='jpeg') or ($imagetype=='jpg')) {
  15. $image = imagecreatefromjpeg($image_file);
  16. } else {
  17. if (($imagetype=='GIF') or ($imagetype=='gif')) {
  18. $image = imagecreatefromgif($image_file);
  19. } else {
  20. $image = imagecreatefrompng($image_file);
  21. }
  22. }
  23.  
  24.  
  25. $size = getimagesize($image_file);
  26. // Top-left corner
  27. $background = imagecreatetruecolor($size[0],$size[1]);
  28. imagecopymerge($background, $image, 0, 0, 0, 0, $size[0], $size[1], 100);
  29. $startx=$size[0]*2-1;
  30. $starty=$size[1]*2-1;
  31. $im_temp = imagecreatetruecolor($startx,$starty);
  32. imagecopyresampled($im_temp, $background, 0, 0, 0, 0, $startx, $starty, $size[0], $size[1]);
  33. $bg = imagecolorallocate($im_temp, hexdec(substr($backcolor,0,2)),hexdec(substr($backcolor,2,2)),hexdec(substr($backcolor,4,2)));
  34. $fg = imagecolorallocate($im_temp, hexdec(substr($forecolor,0,2)),hexdec(substr($forecolor,2,2)),hexdec(substr($forecolor,4,2)));
  35.  
  36. if ($topleft == true) {
  37. imagearc($im_temp, $startsize, $startsize, $arcsize, $arcsize, 180,270,$bg);
  38. imagefilltoborder($im_temp,0,0,$bg,$bg);
  39. }
  40.  
  41. // Bottom-left corner
  42. if ($bottomleft == true) {
  43. imagearc($im_temp, $startsize, $starty-$startsize,$arcsize, $arcsize, 90,180,$bg);
  44. imagefilltoborder($im_temp,0,$starty,$bg,$bg);
  45. }
  46.  
  47. // Bottom-right corner
  48. if ($bottomright == true) {
  49. imagearc($im_temp, $startx-$startsize, $starty-$startsize,$arcsize, $arcsize, 0,90,$bg);
  50. imagefilltoborder($im_temp,$startx,$starty,$bg,$bg);
  51. }
  52.  
  53. // Top-right corner
  54. if ($topright == true) {
  55. imagearc($im_temp, $startx-$startsize, $startsize,$arcsize, $arcsize, 270,360,$bg);
  56. imagefilltoborder($im_temp,$startx,0,$bg,$bg);
  57. }
  58.  
  59.  
  60. $newimage = imagecreatetruecolor($size[0],$size[1]);
  61. imagecopyresampled($image, $im_temp, 0, 0, 0, 0, $size[0],$size[1],$startx, $starty);
  62.  
  63. // Output final image
  64. header("Content-type: image/png");
  65. imagepng($image);
  66. imagedestroy($image);
  67. imagedestroy($background);
  68. imagedestroy($im_temp);
  69. ?>

以上是关于图像上的圆角的主要内容,如果未能解决你的问题,请参考以下文章

平铺后如何在QML中获得圆角按钮图像

如何在iOS中将方形图像屏蔽为圆角图像?

PHP图像动态调整大小和圆角图像

如何设置图像视图的圆角? [复制]

UITableView 上的圆角

如何在android中的自定义圆角图像视图中设置图像