This article is an example of how PHP generates rounded-corner images. Share to everyone for your reference. Specifically as follows:
Copy Code code 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, 0,0,0,0, $size [0], $size [1],100);
$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, 0,2)), Hexdec (substr ($backcolor, 2,2)), Hexdec (substr ($ backcolor,4,2)));
$FG = Imagecolorallocate ($im _temp, Hexdec (substr ($forecolor, 0,2)), Hexdec (substr ($forecolor, 2,2)), 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,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 your PHP program design.