18c02-1.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 91 行

PHP
91
字号
<?php// First of all, create a function that will automatically make a// dropshadowed box. give it the coordinates of the primary box// and the offset that you want the drop to be.  It assumes lower right.function i_filledrectangledropshadow($g,         $x1, $y1, $x2, $y2,         $drop, $color, $shcolor) {    // First draw the shadow box offset appropriately    imagefilledrectangle($g, $x1 + $drop, $y1 + $drop,         $x2 + $drop, $y2 + $drop, $shcolor);        // Now the main box:    imagefilledrectangle($g, $x1, $y1, $x2, $y2, $color); }// Create a function similar to above, but that creates an outline rectangle//  with the drop shadow.  A more normal looking drop shadow box.function i_rectangledropshadow($g,         $x1, $y1, $x2, $y2,         $drop, $color, $shcolor, $border) {    // Time to cheat a bit.  First call our previous function:    i_filledrectangledropshadow($g, $x1, $y1, $x2, $y2,         $drop, $color, $shcolor);        // Now draw a regular rectangle on top of it:    imagerectangle($g, $x1, $y1, $x2, $y2, $border);}// A function to draw a filled rectangle with rounded corners:// Just like drawing a rectangle, but also specify a radius for the corners.function i_filledroundedrectangle($g, $x1, $y1, $x2, $y2, $color, $radius) {    // We need to know the diameter too:    $d = $radius * 2;        // Going to cheat slightly to accomplish this.  First draw four circles    //  at the corners of this box:    imagefilledellipse($g, $x1 + $radius, $y1 + $radius, $d, $d, $color);    imagefilledellipse($g, $x2 - $radius, $y1 + $radius, $d, $d, $color);    imagefilledellipse($g, $x1 + $radius, $y2 - $radius, $d, $d, $color);    imagefilledellipse($g, $x2 - $radius, $y2 - $radius, $d, $d, $color);        // Now fill in the middle, two well placed rectangles will do it.    imagefilledrectangle($g, $x1+$radius, $y1, $x2-$radius, $y2, $color);    imagefilledrectangle($g, $x1, $y1+$radius, $x2, $y2-$radius, $color);}// Now a version that will just draw an online of a rounded rectanglefunction i_roundedrectangle($g,         $x1, $y1, $x2, $y2,         $color, $border, $radius) {    // This could be implemented by doing calls of imagearc and imageline    //  similar to the previous function.  But since we have that function    //  we can cheat:      // Just call it twice with the inner color, and the border.    i_filledroundedrectangle($g, $x1, $y1, $x2, $y2, $border, $radius);    i_filledroundedrectangle($g, $x1 + 1, $y1 + 1, $x2 - 1, $y2 - 1,         $color, $radius);}// We are going to call each of these to test them.// Create a blank image to do this on.$gfx = imagecreatetruecolor(200, 200);// Declare a few colors we will use:$black = imagecolorallocate($gfx, 0, 0, 0);$gray = imagecolorallocate($gfx, 120, 120, 120);$white = imagecolorallocate($gfx, 255, 255, 255);$blue = imagecolorallocate($gfx, 0, 0, 255);// Make almost entire background white.imagefilledrectangle($gfx, 1, 1, 198, 198, $white);// Turn on antialiasing so that curvy things look better.imageantialias($gfx, true);// Ok, try to make a blue box with a gray drop shadow:i_filledrectangledropshadow($gfx, 5, 5, 50, 40, 5, $blue, $gray);// How about a basic white box, with black outline, with a drop shadowi_rectangledropshadow($gfx, 5, 60, 50, 100, 5, $white, $gray, $black);// Insert a filled rounded rectangle, blue sounds goodi_filledroundedrectangle($gfx, 70, 5, 150, 50, $blue, 15);// Now how about a rectangle with rounded corners, not filled in:i_roundedrectangle($gfx, 70, 65, 160, 100, $white, $black, 15);// Output our sample as a PNGheader('Content-type: image/png');imagepng($gfx);?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?