>  기사  >  백엔드 개발  >  php_php 팁에서 둥근 이미지를 생성하는 방법

php_php 팁에서 둥근 이미지를 생성하는 방법

WBOY
WBOY원래의
2016-05-16 20:18:06983검색

이 기사의 예에서는 PHP에서 둥근 이미지를 생성하는 방법을 설명합니다. 참고할 수 있도록 모든 사람과 공유하세요. 세부 내용은 다음과 같습니다.

코드 복사 코드는 다음과 같습니다.
$image_file = $_GET['src'];
$corner_radius = isset($_GET['radius']) ? $_GET['radius'] : 20; // 기본 코너 반경은 20px로 설정됩니다.
$topleft = (isset($_GET['topleft']) and $_GET['topleft'] == "no") ? false : true; // 기본적으로 왼쪽 상단 둥근 모서리가 표시됩니다
$bottomleft = (isset($_GET['bottomleft']) and $_GET['bottomleft'] == "no") ? false : true; // 기본적으로 왼쪽 하단 둥근 모서리가 표시됩니다
$bottomright = (isset($_GET['bottomright']) and $_GET['bottomright'] == "no") ? false : true; // 기본적으로 오른쪽 아래 둥근 모서리가 표시됩니다
$topright = (isset($_GET['topright']) and $_GET['topright'] == "no") ? false : true; // 기본적으로 오른쪽 상단이 둥근 모서리로 표시됩니다
$imagetype=strtolower($_GET['imagetype']);
$backcolor=$_GET['backcolor'];
$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);
// 왼쪽 상단
$배경 = imagecreatetruecolor($size[0],$size[1]);
imagecopymerge($배경,$이미지,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("콘텐츠 유형: 이미지/png");
imagepng($image);
imagedestroy($image);
imagedestroy($배경);
imagedestroy($im_temp);
?>

이 기사가 모든 사람의 PHP 프로그래밍 설계에 도움이 되기를 바랍니다.

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.