This article mainly introduces the php method for generating rounded corner images, which involves php image operations and is of great practical value, for more information, see the example in this article. Share it with you for your reference. The details are as follows:
The code is as follows:
<? Php
$ Image_file = $ _ GET ['src'];
$ Corner_radius = isset ($ _ GET ['radius '])? $ _ GET ['radius ']: 20; // The default corner radius is set to 20px
$ Topleft = (isset ($ _ GET ['topleft']) and $ _ GET ['topleft'] = "no ")? False: true; // Top-left rounded corner is shown by default
$ Bottomleft = (isset ($ _ GET ['bottomleft']) and $ _ GET ['bottomleft'] = "no ")? False: true; // Bottom-left rounded corner is shown by default
$ Bottomright = (isset ($ _ GET ['bottomright']) and $ _ GET ['bottomright'] = "no ")? False: true; // Bottom-right rounded corner is shown by default
$ Topright = (isset ($ _ GET ['topright']) and $ _ GET ['topright'] = "no ")? False: true; // Top-right rounded corner is shown by default
$ Imagetype = strtolower ($ _ GET ['imagetype ']);
$ Backcolor = $ _ GET ['backcolor'];
$ Endsize = $ corner_radius;
$ Startsize = $ endsize * 3-1;
$ Arcsize = $ startsize * 2 + 1;
If ($ imagetype = 'jpeg ') or ($ imagetype = 'jpg ')){
$ Image = imagecreatefromjpeg ($ image_file );
} Else {
If ($ imagetype = 'GIF') or ($ imagetype = 'GIF ')){
$ Image = imagecreatefromgif ($ image_file );
} Else {
$ Image = imagecreatefrompng ($ image_file );
}
}
$ Size = getimagesize ($ image_file );
// Top-left corner
$ Background = imagecreatetruecolor ($ size [0], $ size [1]);
Imagecopymerge ($ background, $ image, 100, $ size [0], $ size [1 );
$ Startx = $ size [0] * 2-1;
$ Starty = $ size [1] * 2-1;
$ Im_temp = imagecreatetruecolor ($ startx, $ starty );
Imagecopyresampled ($ im_temp, $ background, 0, 0, 0, 0, $ startx, $ starty, $ size [0], $ size [1]);
$ Bg = imagecolorallocate ($ im_temp, hexdec (substr ($ backcolor,), hexdec (substr ($ backcolor,), hexdec (substr ($ backcolor, 4, 2 )));
$ Fg = imagecolorallocate ($ im_temp, hexdec (substr ($ forecolor,), hexdec (substr ($ forecolor,), hexdec (substr ($ forecolor, 4, 2 )));
If ($ topleft = true ){
Imagearc ($ im_temp, $ startsize, $ startsize, $ arcsize, $ arcsize, 180,270, $ bg );
Imagefilltoborder ($ im_temp, 0, 0, $ bg, $ bg );
}
// Bottom-left corner
If ($ bottomleft = true ){
Imagearc ($ im_temp, $ startsize, $ starty-$ startsize, $ arcsize, $ arcsize, 90,180, $ bg );
Imagefilltoborder ($ im_temp, 0, $ starty, $ bg, $ bg );
}
// Bottom-right corner
If ($ bottomright = true ){
Imagearc ($ im_temp, $ startx-$ startsize, $ starty-$ startsize, $ arcsize, $ arcsize, 0, 90, $ bg );
Imagefilltoborder ($ im_temp, $ startx, $ starty, $ bg, $ bg );
}
// Top-right corner
If ($ topright = true ){
Imagearc ($ im_temp, $ startx-$ startsize, $ startsize, $ arcsize, $ arcsize, 270,360, $ bg );
Imagefilltoborder ($ im_temp, $ startx, 0, $ bg, $ bg );
}
$ Newimage = imagecreatetruecolor ($ size [0], $ size [1]);
Imagecopyresampled ($ image, $ im_temp, 0, 0, 0, $ size [0], $ size [1], $ startx, $ starty );
// Output final image
Header ("Content-type: image/png ");
Imagepng ($ image );
Imagedestroy ($ image );
Imagedestroy ($ background );
Imagedestroy ($ im_temp );
?>
I hope this article will help you with php programming.