ホームページ  >  記事  >  バックエンド開発  >  php_PHP チュートリアルで角の丸い画像を生成する方法

php_PHP チュートリアルで角の丸い画像を生成する方法

WBOY
WBOYオリジナル
2016-07-13 09:57:43977ブラウズ

phpで角画像を生成する方法

具体的には以下の通り:

代码如下:

$image_file = $_GET['src'];
$corner_radius = isset($_GET['radius']) ? $_GET['半径'] : 20; // デフォルトの角の半径は 20px に設定されています
$topleft = (isset($_GET['topleft']) および $_GET['topleft'] == "no") ?真偽; // デフォルトでは左上の丸い角が表示されます
$bottomleft = (isset($_GET['bottomleft']) および $_GET['bottomleft'] == "いいえ") ?真偽; // デフォルトでは左下の丸い角が表示されます
$bottomright = (isset($_GET['bottomright']) および $_GET['bottomright'] == "いいえ") ?真偽; // 右下の丸い角がデフォルトで表示されます
$topright = (isset($_GET['topright']) および $_GET['topright'] == "いいえ") ?真偽; // 右上の丸い角がデフォルトで表示されます
$imagetype=strto lower($_GET['imagetype']);
$backcolor=$_GET['バックカラー'];
$endsize=$corner_radius;
$startsize=$endsize*3-1;
$arcsize=$startsize*2+1;
if (($imagetype=='jpeg') または ($imagetype=='jpg')) {
$image = imagecreatefromjpeg($image_file);
} その他 {
if (($imagetype=='GIF') または ($imagetype=='gif')) {
$image = imagecreatefromgif($image_file);
} その他 {
$image = imagecreatefrompng($image_file);
}
}
$size = getimagesize($image_file);
// 左上隅
$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);
}
// 左下隅
if ($bottomleft == true) {
imagearc($im_temp,$startsize,$starty-$startsize,$arcsize,$arcsize,90,180,$bg);
imagefilltoborder($im_temp,0,$starty,$bg,$bg);
}
// 右下隅
if ($bottomright == true) {
imagearc($im_temp, $startx-$startsize, $starty-$startsize,$arcsize, $arcsize, 0,90,$bg);
imagefilltoborder($im_temp,$startx,$starty,$bg,$bg);
}
// 右上隅
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);
// 最終画像を出力します
header("コンテンツタイプ: image/png");
imagepng($image);
imagedestroy($image);
imagedestroy($background);
imagedestroy($im_temp);
?>

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/980115.html技術記事 php で角画像を生成する方法 具体例: 代償例: ?php $image_file = $_GET['src']; $corner_radius = isset($_GET['radius']) ? $_GET['半径'] : 20; // デフォルトのコーナー...
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。