首頁 > 後端開發 > php教程 > php生成圓角圖片程式碼

php生成圓角圖片程式碼

WBOY
發布: 2016-07-25 08:43:08
原創
1121 人瀏覽過
  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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板