- <?php
- // 출처 및 인용 : http://www.php100.com/html/php/lei/2013/0905/4993.html
- // GET 파라미터로 가로 막대 그래프 적용 위한 설정
- if(ctype_print($_GET["h_bar"])) $h_bar = explode(",", $_GET['h_bar']);
- else $h_bar = array(20, 10, 50, 40, 33, 26, 3);
- //막대 총 수
- $bar_count = count($h_bar);
- // 전체 화면
- $width = 250;
- $height = 200;
- // 간격
- $padding = 5;
- // 막대 하나 길이
- $bar_one = $width / $bar_count;
- // 이미지 생성
- $im = imagecreate($width, $height);
- $bgc1 = imagecolorallocate ($im, 0xcc, 0xcc, 0xcc);
- $bgc2 = imagecolorallocate ($im, 0x7f, 0x7f, 0x7f);
- $tc = imagecolorallocate ($im, 0xff, 0xff, 0xff);
- // 이미지 배경색
- imagefilledrectangle ($im, 0, 0, $width, $height, $tc);
- // 최대값
- $max = max($h_bar);
- // 각각의 막대 그림
- for($i = 0; $i < $bar_count; $i++){
- $bar_h = ($height / 100) * (($h_bar[$i] / $max) *100 );
- $x1 = $i*$bar_one;
- $y1 = $height - $bar_h;
- $x2 = (($i+1)*$bar_one)-$padding;
- $y2 = $height;
- imagefilledrectangle ($im, $x1, $y1, $x2, $y2, $bgc1);
- imagefilledrectangle ($im, $x2, $y1, $x2, $y2, $bgc2);
- }
- // 이미지 타입 전송
- header("Content-Type: image/png");
- // 이미지 출력
- imagepng($im);
- // 이미지 자원 제거
- //imagedestroy($img);
- ?>
--------------------------------------------------------------------------------------------
HTMLtag에서
<img src="imageinsert.php?h_bar?=50,30,15,32,42,13,43">
이런식으로 쓰이면 이미지를 출력합니다.
출처 및 인용 : http://www.php100.com/html/php/lei/2013/0905/4993.html
'php5 > 이미지관련함수' 카테고리의 다른 글
막대그래프-그리기2 (0) | 2014.01.14 |
---|---|
이미지 넓이 반환 - int imagesx ( resource $image ) (0) | 2014.01.14 |
이미지 생성 문법 (0) | 2014.01.14 |
이미지 GD라이브러리 정보 배열 반환 - array gd_info ( void ) (0) | 2014.01.14 |
이미지 파일 정보 배열 반환 - array getimagesize ( string $filename ) (0) | 2014.01.14 |