SMS처리 도우미
Tip&Tech PHP

PHP 썸네일 만들기

작성자 소스놀이터 작성일 2023-01-04 18:45:04 조회수 1100 E-mail ldwin@naver.com

PHP 썸네일 생성 함수입니다.

인자를 설명드리면...

$source_file : 이미 존재하는 이미지 파일명 (경로 포함)
$thumbnail_file : $source_file로부터 만들어지는 썸네일 파일명 (경로 포함)
$wanted_width : 만들길 원하는 썸네일의 폭
$wanted_height : 만들길 원하는 썸네일의 높이

사용을 위한 필수 조건
1. 이 함수를 사용하려면, php.ini의 allow_url_fopen 옵션이 허용되어 있어야 합니다.
2. 아울러 GD 라이브러리가 설치되어 있고, PHP에서 사용 가능한 상태여야 합니다.

 

	function make_thumb($source_file, $thumbnail_file, $wanted_width,$wanted_height)
	{
		$source_image = imagecreatefromstring(file_get_contents($source_file)); //파일읽기
		$width = imagesx($source_image);
		$height = imagesy($source_image);

		$virtual_image = imagecreatetruecolor($wanted_width, $wanted_height); //가상 이미지 만들기

		imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $wanted_width, $wanted_height, $width, $height); //사이즈 변경하여 복사

		$return = false;
		if(imagepng($virtual_image, $thumbnail_file)) // png파일로 썸네일 생성
		{
			$return = true;
		}
		return $return;
	}

Recent Posts

Tip&Tech 최근 글

Tip&Tech 게시판의 PHP 관련 최근 글입니다.

같이 볼 수 있는 글을 준비 중입니다.

이전 글
다음 글
X
로그기록