<?php #php##source###image####썸네일을 원본의 비율대로 생성하여 주는 함수 - netpbm를 이용 ?>
<?php
/*제작자 : 유창화
사용제한 : 사용은 자유롭습니다. 단, 강의나 책의 내용으로서 사용될 경우 허락을 받으셔야 합니다.*/
//모든 에러를 출력하도록 설정한다.
error_reporting(E_ALL);
//기본 함수 모음을 인클루드
define('YFUNCTION_INCLUDED', true);// 소스를 보여주기 위한 상수
include_once './Yfunction.php';
//처리시간 측정시작
$Ystarttime = Yget_microtime();
//썸네일 이미지 사이지 결정하여 썸네일 생성
//$src_file_size, $dest_file_size 이미지 정보를 담은 배열 0은 너비 1은 높이
function Ysumnail_rule($src_file, $dest_file, $src_file_size, $dest_file_size, $image_quality=90, $lib='gd'){
//생성도중 에러가 날수 있는 것들을 체크 하여 return false
if (!is_array($src_file_size) || !is_array($dest_file_size) || empty($src_file_size[0]) || empty($src_file_size[1]) || empty($dest_file_size[0]) || empty($dest_file_size[0])) {
return false;
}
//$lib 확인후 조건에 맞지 않으면 기본값 세팅
if (empty($lib) || ($lib != 'gd' && $lib != 'netpbm')) $lib = 'gd';
$rate = $src_file_size[1] / $src_file_size[0];
$temp[1] = (int)($dest_file_size[0] * $rate);
if ($dest_file_size[1] < $temp[1]) {
$rate = $src_file_size[0] / $src_file_size[1];
$dest_file_size[0] = (int)($dest_file_size[1] * $rate);
}
else{
$dest_file_size[1] = $temp[1];
}
//썸네일의 너비나 높이가 10 미만인것은 만들지 않는다.
if ($dest_file_size[0] < 10 || $dest_file_size[1] < 10) {
return false;
}
//썸네일 이미지가 원본이미지 크기보다 크게 설정되었을 경우, 원본이미지와 동일하게
if ($dest_file_size[0] > $src_file_size[0]) {
$dest_file_size = $src_file_size;
}
if ($lib == 'netpbm') return Ymake_sumnail_netpbm($src_file, $dest_file, $src_file_size, $dest_file_size, $image_quality);
else return Ymake_sumnail_gd($src_file, $dest_file, $src_file_size, $dest_file_size, $image_quality);
}
//섬네일 생성
function Ymake_sumnail_netpbm($src_file, $dest_file, $src_file_size, $dest_file_size, $image_quality=90){
//생성도중 에러가 날수 있는 것들을 체크 하여 return false
if (empty($src_file) || empty($dest_file) || !is_file($src_file) || !is_array($src_file_size) || !is_array($dest_file_size) || empty($src_file_size[0]) || empty($src_file_size[1]) || empty($src_file_size[2]) || empty($dest_file_size[0]) || empty($dest_file_size[0])) {
return false;
}
//$image_quality 확인후 조건에 맞지 않으면 기본값 세팅
if(!is_numeric($image_quality) || empty($image_quality)) $image_quality = 90;
//원본사이즈보다 썸네일 사이즈가 더 크면 원본사이즈와 같게 썸네일을 생성
if ($dest_file_size[0] > $src_file_size[0]) {
$dest_file_size = $src_file_size;
}
$temp_pnm = $src_file . '.pnm';
switch($src_file_size[2]) {
case 1: // GIF image
@exec( "giftopnm " . $src_file . " > " . $temp_pnm);
break;
case 2: // JPEG image
@exec( "jpegtopnm " . $src_file . " > " . $temp_pnm);
break;
case 3: // PNG image
@exec( "pngtopnm " . $src_file . " > " . $temp_pnm);
break;
case 6: // BMP image
@exec( "bmptopnm " . $src_file . " > " . $temp_pnm);
break;
default: // 정해진 이외의 포맷은 return false
return false;
}
@exec( "pnmscale -xy " . $dest_file_size[0] . " " . $dest_file_size[1] . " " . $temp_pnm . " | cjpeg -progressive -optimize -smooth 5 -quality " . $image_quality . " -outfile " . $dest_file);
@unlink($temp_pnm);
//퍼미션 변경가능 여부를 가지고 썸네일 생성 실패 판단
return @chmod($dest_file, 0777);
}
$src_file = './temp/test.png';
$src_file_size = getimagesize($src_file);
$dest_file = './temp/s_netpbm_test.png';
$dest_file_size = Array(200, 100);
$result = Ysumnail_rule($src_file, $dest_file, $src_file_size, $dest_file_size, 90, 'netpbm');
echo "<br>png 원본이미지 <img src='" . $src_file . "' border=0>";
if (empty($result)) echo "<br>png 썸네일 생성에 실패하였습니다. 저장디렉토리의 퍼미션이나 원본의 이미지포맷, 또는 netpbm지원여부, 또는 exec 함수의 지원여부를 확인하세요.를 확인하세요.";
else echo "<br>png 썸네일이미지 <img src='" . $dest_file . "' border=0>";
$src_file = './temp/test.jpg';
$src_file_size = getimagesize($src_file);
$dest_file = './temp/s_netpbm_test.jpg';
$dest_file_size = Array(200, 100);
$result = Ysumnail_rule($src_file, $dest_file, $src_file_size, $dest_file_size, 90, 'netpbm');
echo "<br>jpg 원본이미지 <img src='" . $src_file . "' border=0>";
if (empty($result)) echo "<br><b>jpg 썸네일 생성에 실패하였습니다. 저장디렉토리의 퍼미션이나 원본의 이미지포맷, 또는 netpbm지원여부, 또는 exec 함수의 지원여부를 확인하세요.를 확인하세요.</b>";
else echo "<br>jpg 썸네일이미지 <img src='" . $dest_file . "' border=0>";
$src_file = './temp/test.gif';
$src_file_size = getimagesize($src_file);
$dest_file = './temp/s_netpbm_test.gif';
$dest_file_size = Array(200, 100);
$result = Ysumnail_rule($src_file, $dest_file, $src_file_size, $dest_file_size, 90, 'netpbm');
echo "<br>gif 원본이미지 <img src='" . $src_file . "' border=0>";
if (empty($result)) echo "<br><b>gif 썸네일 생성에 실패하였습니다. 저장디렉토리의 퍼미션이나 원본의 이미지포맷, 또는 netpbm지원여부, 또는 exec 함수의 지원여부를 확인하세요.를 확인하세요.</b>";
else echo "<br>gif 썸네일이미지 <img src='" . $dest_file . "' border=0>";
$src_file = './temp/test.bmp';
$src_file_size = getimagesize($src_file);
$dest_file = './temp/s_netpbm_test.bmp';
$dest_file_size = Array(200, 100);
$result = Ysumnail_rule($src_file, $dest_file, $src_file_size, $dest_file_size, 90, 'netpbm');
echo "<br>bmp 원본이미지 <img src='" . $src_file . "' border=0>";
if (empty($result)) echo "<br><b>bmp 썸네일 생성에 실패하였습니다. 저장디렉토리의 퍼미션이나 원본의 이미지포맷, 또는 netpbm지원여부, 또는 exec 함수의 지원여부를 확인하세요.를 확인하세요.</b>";
else echo "<br>bmp 썸네일이미지 <img src='" . $dest_file . "' border=0>";
?>
<?php
//처리시간 출력
Yecho_usetime($Ystarttime);
//설명글 출력
$guide_text = '
[Ysumnail_rule 요약]
썸네일을 원본의 비율대로 생성하여 줍니다.
netpbm를 사용하여 썸네일을 만듭니다.
gif, jpeg, png, bmp 포맷만 가능합니다.
썸네일의 확장자는 원본과 동일하나 파일포맷은 모두 jpeg입니다.
처리속도는 gd로 처리할때보다 조금 더 걸리나 결과물의 질이나 용량은 더 작습니다.
서버에 다음의 rpm이 설치되어야 사용가능합니다.
netpbm
netpbm-progs
[리턴값]
썸네일이나 복사 성공시 true, 실패시 false;
[사용법]
Ysumnail_rule(원본파일 경로, 생성할 썸네일경로, 이미지정보배열(0=>원본 너비, 1=>원본 높이, 2=>이미지포맷정보), 생성할 썸네일정보배열(0=>원본 너비, 1=>원본 높이), 썸네일생성질(100 이하의 숫자입력), 사용할라이브러리 지정(gd 나 netpbm))
';
Yecho_guide($guide_text);
//소스보기 출력
Yecho_viewsource();
?><div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]</div>
<?php
/*제작자 : 유창화
사용제한 : 사용은 자유롭습니다. 단, 강의나 책의 내용으로서 사용될 경우 허락을 받으셔야 합니다.*/
//모든 에러를 출력하도록 설정한다.
error_reporting(E_ALL);
//기본 함수 모음을 인클루드
define('YFUNCTION_INCLUDED', true);// 소스를 보여주기 위한 상수
include_once './Yfunction.php';
//처리시간 측정시작
$Ystarttime = Yget_microtime();
//썸네일 이미지 사이지 결정하여 썸네일 생성
//$src_file_size, $dest_file_size 이미지 정보를 담은 배열 0은 너비 1은 높이
function Ysumnail_rule($src_file, $dest_file, $src_file_size, $dest_file_size, $image_quality=90, $lib='gd'){
//생성도중 에러가 날수 있는 것들을 체크 하여 return false
if (!is_array($src_file_size) || !is_array($dest_file_size) || empty($src_file_size[0]) || empty($src_file_size[1]) || empty($dest_file_size[0]) || empty($dest_file_size[0])) {
return false;
}
//$lib 확인후 조건에 맞지 않으면 기본값 세팅
if (empty($lib) || ($lib != 'gd' && $lib != 'netpbm')) $lib = 'gd';
$rate = $src_file_size[1] / $src_file_size[0];
$temp[1] = (int)($dest_file_size[0] * $rate);
if ($dest_file_size[1] < $temp[1]) {
$rate = $src_file_size[0] / $src_file_size[1];
$dest_file_size[0] = (int)($dest_file_size[1] * $rate);
}
else{
$dest_file_size[1] = $temp[1];
}
//썸네일의 너비나 높이가 10 미만인것은 만들지 않는다.
if ($dest_file_size[0] < 10 || $dest_file_size[1] < 10) {
return false;
}
//썸네일 이미지가 원본이미지 크기보다 크게 설정되었을 경우, 원본이미지와 동일하게
if ($dest_file_size[0] > $src_file_size[0]) {
$dest_file_size = $src_file_size;
}
if ($lib == 'netpbm') return Ymake_sumnail_netpbm($src_file, $dest_file, $src_file_size, $dest_file_size, $image_quality);
else return Ymake_sumnail_gd($src_file, $dest_file, $src_file_size, $dest_file_size, $image_quality);
}
//섬네일 생성
function Ymake_sumnail_netpbm($src_file, $dest_file, $src_file_size, $dest_file_size, $image_quality=90){
//생성도중 에러가 날수 있는 것들을 체크 하여 return false
if (empty($src_file) || empty($dest_file) || !is_file($src_file) || !is_array($src_file_size) || !is_array($dest_file_size) || empty($src_file_size[0]) || empty($src_file_size[1]) || empty($src_file_size[2]) || empty($dest_file_size[0]) || empty($dest_file_size[0])) {
return false;
}
//$image_quality 확인후 조건에 맞지 않으면 기본값 세팅
if(!is_numeric($image_quality) || empty($image_quality)) $image_quality = 90;
//원본사이즈보다 썸네일 사이즈가 더 크면 원본사이즈와 같게 썸네일을 생성
if ($dest_file_size[0] > $src_file_size[0]) {
$dest_file_size = $src_file_size;
}
$temp_pnm = $src_file . '.pnm';
switch($src_file_size[2]) {
case 1: // GIF image
@exec( "giftopnm " . $src_file . " > " . $temp_pnm);
break;
case 2: // JPEG image
@exec( "jpegtopnm " . $src_file . " > " . $temp_pnm);
break;
case 3: // PNG image
@exec( "pngtopnm " . $src_file . " > " . $temp_pnm);
break;
case 6: // BMP image
@exec( "bmptopnm " . $src_file . " > " . $temp_pnm);
break;
default: // 정해진 이외의 포맷은 return false
return false;
}
@exec( "pnmscale -xy " . $dest_file_size[0] . " " . $dest_file_size[1] . " " . $temp_pnm . " | cjpeg -progressive -optimize -smooth 5 -quality " . $image_quality . " -outfile " . $dest_file);
@unlink($temp_pnm);
//퍼미션 변경가능 여부를 가지고 썸네일 생성 실패 판단
return @chmod($dest_file, 0777);
}
$src_file = './temp/test.png';
$src_file_size = getimagesize($src_file);
$dest_file = './temp/s_netpbm_test.png';
$dest_file_size = Array(200, 100);
$result = Ysumnail_rule($src_file, $dest_file, $src_file_size, $dest_file_size, 90, 'netpbm');
echo "<br>png 원본이미지 <img src='" . $src_file . "' border=0>";
if (empty($result)) echo "<br>png 썸네일 생성에 실패하였습니다. 저장디렉토리의 퍼미션이나 원본의 이미지포맷, 또는 netpbm지원여부, 또는 exec 함수의 지원여부를 확인하세요.를 확인하세요.";
else echo "<br>png 썸네일이미지 <img src='" . $dest_file . "' border=0>";
$src_file = './temp/test.jpg';
$src_file_size = getimagesize($src_file);
$dest_file = './temp/s_netpbm_test.jpg';
$dest_file_size = Array(200, 100);
$result = Ysumnail_rule($src_file, $dest_file, $src_file_size, $dest_file_size, 90, 'netpbm');
echo "<br>jpg 원본이미지 <img src='" . $src_file . "' border=0>";
if (empty($result)) echo "<br><b>jpg 썸네일 생성에 실패하였습니다. 저장디렉토리의 퍼미션이나 원본의 이미지포맷, 또는 netpbm지원여부, 또는 exec 함수의 지원여부를 확인하세요.를 확인하세요.</b>";
else echo "<br>jpg 썸네일이미지 <img src='" . $dest_file . "' border=0>";
$src_file = './temp/test.gif';
$src_file_size = getimagesize($src_file);
$dest_file = './temp/s_netpbm_test.gif';
$dest_file_size = Array(200, 100);
$result = Ysumnail_rule($src_file, $dest_file, $src_file_size, $dest_file_size, 90, 'netpbm');
echo "<br>gif 원본이미지 <img src='" . $src_file . "' border=0>";
if (empty($result)) echo "<br><b>gif 썸네일 생성에 실패하였습니다. 저장디렉토리의 퍼미션이나 원본의 이미지포맷, 또는 netpbm지원여부, 또는 exec 함수의 지원여부를 확인하세요.를 확인하세요.</b>";
else echo "<br>gif 썸네일이미지 <img src='" . $dest_file . "' border=0>";
$src_file = './temp/test.bmp';
$src_file_size = getimagesize($src_file);
$dest_file = './temp/s_netpbm_test.bmp';
$dest_file_size = Array(200, 100);
$result = Ysumnail_rule($src_file, $dest_file, $src_file_size, $dest_file_size, 90, 'netpbm');
echo "<br>bmp 원본이미지 <img src='" . $src_file . "' border=0>";
if (empty($result)) echo "<br><b>bmp 썸네일 생성에 실패하였습니다. 저장디렉토리의 퍼미션이나 원본의 이미지포맷, 또는 netpbm지원여부, 또는 exec 함수의 지원여부를 확인하세요.를 확인하세요.</b>";
else echo "<br>bmp 썸네일이미지 <img src='" . $dest_file . "' border=0>";
?>
<?php
//처리시간 출력
Yecho_usetime($Ystarttime);
//설명글 출력
$guide_text = '
[Ysumnail_rule 요약]
썸네일을 원본의 비율대로 생성하여 줍니다.
netpbm를 사용하여 썸네일을 만듭니다.
gif, jpeg, png, bmp 포맷만 가능합니다.
썸네일의 확장자는 원본과 동일하나 파일포맷은 모두 jpeg입니다.
처리속도는 gd로 처리할때보다 조금 더 걸리나 결과물의 질이나 용량은 더 작습니다.
서버에 다음의 rpm이 설치되어야 사용가능합니다.
netpbm
netpbm-progs
[리턴값]
썸네일이나 복사 성공시 true, 실패시 false;
[사용법]
Ysumnail_rule(원본파일 경로, 생성할 썸네일경로, 이미지정보배열(0=>원본 너비, 1=>원본 높이, 2=>이미지포맷정보), 생성할 썸네일정보배열(0=>원본 너비, 1=>원본 높이), 썸네일생성질(100 이하의 숫자입력), 사용할라이브러리 지정(gd 나 netpbm))
';
Yecho_guide($guide_text);
//소스보기 출력
Yecho_viewsource();
?><div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]</div>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 1130 | 18년 전 | 2462 | ||
| 1129 | 18년 전 | 2445 | ||
| 1128 | 18년 전 | 2317 | ||
| 1127 | 18년 전 | 2550 | ||
| 1126 |
|
18년 전 | 3846 | |
| 1125 | 18년 전 | 3646 | ||
| 1124 |
|
18년 전 | 2080 | |
| 1123 | 18년 전 | 2015 | ||
| 1122 | 18년 전 | 1552 | ||
| 1121 | 18년 전 | 3880 | ||
| 1120 | 18년 전 | 5891 | ||
| 1119 | 18년 전 | 6977 | ||
| 1118 | 18년 전 | 2460 | ||
| 1117 |
BEST79
|
18년 전 | 2705 | |
| 1116 | 18년 전 | 4173 | ||
| 1115 | 18년 전 | 2169 | ||
| 1114 |
|
18년 전 | 3623 | |
| 1113 | 18년 전 | 2869 | ||
| 1112 | 18년 전 | 2724 | ||
| 1111 | 18년 전 | 2191 | ||
| 1110 | 18년 전 | 2459 | ||
| 1109 | 18년 전 | 2590 | ||
| 1108 | 18년 전 | 3081 | ||
| 1107 | 18년 전 | 3725 | ||
| 1106 | 18년 전 | 3264 | ||
| 1105 | 18년 전 | 2771 | ||
| 1104 |
|
18년 전 | 2266 | |
| 1103 | 18년 전 | 2933 | ||
| 1102 | 18년 전 | 3021 | ||
| 1101 | 18년 전 | 2534 | ||
| 1100 | 18년 전 | 2295 | ||
| 1099 | 18년 전 | 3323 | ||
| 1098 | 18년 전 | 4844 | ||
| 1097 | 18년 전 | 5068 | ||
| 1096 | 18년 전 | 2288 | ||
| 1095 | 18년 전 | 2183 | ||
| 1094 | 18년 전 | 4994 | ||
| 1093 | 18년 전 | 8952 | ||
| 1092 | 18년 전 | 2036 | ||
| 1091 |
DeepnBlue
|
18년 전 | 4916 | |
| 1090 |
|
18년 전 | 4362 | |
| 1089 |
도날드주주
|
18년 전 | 2602 | |
| 1088 |
|
18년 전 | 4957 | |
| 1087 | 18년 전 | 2783 | ||
| 1086 | 18년 전 | 3665 | ||
| 1085 | 18년 전 | 2614 | ||
| 1084 | 18년 전 | 3427 | ||
| 1083 | 18년 전 | 1938 | ||
| 1082 | 18년 전 | 5370 | ||
| 1081 | 18년 전 | 1684 | ||
| 1080 | 18년 전 | 6047 | ||
| 1079 |
|
18년 전 | 2871 | |
| 1078 | 18년 전 | 6032 | ||
| 1077 |
|
18년 전 | 6833 | |
| 1076 | 18년 전 | 3725 | ||
| 1075 | 18년 전 | 2204 | ||
| 1074 |
hwatta
|
18년 전 | 2093 | |
| 1073 | 18년 전 | 6894 | ||
| 1072 | 18년 전 | 2389 | ||
| 1071 | 18년 전 | 3945 | ||
| 1070 |
|
18년 전 | 5341 | |
| 1069 | 18년 전 | 2688 | ||
| 1068 | 18년 전 | 1736 | ||
| 1067 | 18년 전 | 1568 | ||
| 1066 | 18년 전 | 1516 | ||
| 1065 | 18년 전 | 1796 | ||
| 1064 | 18년 전 | 1786 | ||
| 1063 | 18년 전 | 1775 | ||
| 1062 | 18년 전 | 1714 | ||
| 1061 | 18년 전 | 2502 | ||
| 1060 | 18년 전 | 2301 | ||
| 1059 | 18년 전 | 3461 | ||
| 1058 | 18년 전 | 2588 | ||
| 1057 | 18년 전 | 2573 | ||
| 1056 | 18년 전 | 3408 | ||
| 1055 | 18년 전 | 4620 | ||
| 1054 | 18년 전 | 2958 | ||
| 1053 | 18년 전 | 2796 | ||
| 1052 | 18년 전 | 3343 | ||
| 1051 | 18년 전 | 6274 | ||
| 1050 | 18년 전 | 2177 | ||
| 1049 | 18년 전 | 1986 | ||
| 1048 | 18년 전 | 1937 | ||
| 1047 | 18년 전 | 2001 | ||
| 1046 | 18년 전 | 3188 | ||
| 1045 | 18년 전 | 2258 | ||
| 1044 | 18년 전 | 1947 | ||
| 1043 | 18년 전 | 1616 | ||
| 1042 | 18년 전 | 2077 | ||
| 1041 | 18년 전 | 3357 | ||
| 1040 | 18년 전 | 3225 | ||
| 1039 | 18년 전 | 1911 | ||
| 1038 | 18년 전 | 1481 | ||
| 1037 | 18년 전 | 3179 | ||
| 1036 | 18년 전 | 2053 | ||
| 1035 | 18년 전 | 1613 | ||
| 1034 | 18년 전 | 2836 | ||
| 1033 | 18년 전 | 1965 | ||
| 1032 | 18년 전 | 1840 | ||
| 1031 | 18년 전 | 1810 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기