2018년 5월 22일 화요일

[PHP예제] 138 이미지 생성 및 저장




 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<?php
// Content-Type 헤더를 전송함
header('Content-type: image/png');
// IE가 Content-Type 헤더를 무시하지 않게 함
header('X-Content-Type-Optoins: nosniff');

// 이미지를 생성함
$image = imagecreatetruecolor(400, 300);

// 이미지의 배경색에 빨간색을 설정함
// 제2~4인수에 RGB의 각 값을 0~255의 정수로 지정함
$bg_color = imagecolorallocate($image, 255, 0, 0);
imagefill($image, 0, 0, $bg_color);

// 브라우저에 이미지를 출력함
imagepng($image);

// 이미지를 삭제하고 메모리 점유를 해제함
imagedestory($image);




  • 이미지를 파일로 저장하고 싶을 때
    • imagepng() 함수의 제2인수에 파일명을 지정하여 이미지를 파일에 저장
      • imagepng($image, $fileName)

댓글 없음:

댓글 쓰기