[GD] gif/jp(e)g/png 를 이용한 gd 버젼별 썸네일 생성
// 호출시
put_gdimage('원본파일명', 생성가로, 생성세로, '저장될파일명');
// 정상생성여부 확인시 : 정상생성시 1을 리턴, 이외는 실패
// gd 이미지 생성
// $img_name = 생성에 사용될 원본 파일명, $width = 생성이미지 가로크기, $height = 생성이미지 세로크기, $save_name = 저장될 파일명
function put_gdimage($img_name, $width, $height, $save_name){
// GD 버젼체크
$gd = gd_info();
$gdver = substr(preg_replace("/[^0-9]/", "", $gd['GD Version']), 0, 1);
if(!$gdver) return "GD 버젼체크 실패거나 GD 버젼이 1 미만입니다.";
$srcname = "../upload/goods/".$img_name;
$timg = getimagesize($srcname);
if($timg[2] != 1 && $timg[2] != 2 && $timg[2] != 3) return "확장자가 jp(e)g/png/gif 가 아닙니다.";
// jpg, jpeg
if($timg[2] == 2){
$cfile = imagecreatefromjpeg($srcname);
// gd 버전별로
if($gdver == 2){
$dest = imagecreatetruecolor($width, $height);
imagecopyresampled($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
}else{
$dest = imagecreate($width, $height);
imagecopyresized($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
}
imagejpeg($dest, "../upload/goods/".$save_name, 90);
// png
}else if($timg[2] == 3){
$cfile = imagecreatefrompng($srcname);
if($gdver == 2){
$dest = imagecreatetruecolor($width, $height);
imagecopyresampled($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
}else{
$dest = imagecreate($width, $height);
imagecopyresized($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
}
imagepng($dest, "../upload/goods/".$save_name, 90);
// gif
}else if($timg[2] == 1){
$cfile = imagecreatefromgif($srcname);
if($gdver == 2){
$dest = imagecreatetruecolor($width, $height);
imagecopyresampled($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
}else{
$dest = imagecreate($width, $height);
imagecopyresized($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
}
imagegif($dest, "../upload/goods/".$save_name, 90);
}
// 메모리에 있는 그림 삭제
imagedestroy($dest);
return 1;
}
관리자님 g4도 탭 치환좀 해주십시오.
put_gdimage('원본파일명', 생성가로, 생성세로, '저장될파일명');
// 정상생성여부 확인시 : 정상생성시 1을 리턴, 이외는 실패
// gd 이미지 생성
// $img_name = 생성에 사용될 원본 파일명, $width = 생성이미지 가로크기, $height = 생성이미지 세로크기, $save_name = 저장될 파일명
function put_gdimage($img_name, $width, $height, $save_name){
// GD 버젼체크
$gd = gd_info();
$gdver = substr(preg_replace("/[^0-9]/", "", $gd['GD Version']), 0, 1);
if(!$gdver) return "GD 버젼체크 실패거나 GD 버젼이 1 미만입니다.";
$srcname = "../upload/goods/".$img_name;
$timg = getimagesize($srcname);
if($timg[2] != 1 && $timg[2] != 2 && $timg[2] != 3) return "확장자가 jp(e)g/png/gif 가 아닙니다.";
// jpg, jpeg
if($timg[2] == 2){
$cfile = imagecreatefromjpeg($srcname);
// gd 버전별로
if($gdver == 2){
$dest = imagecreatetruecolor($width, $height);
imagecopyresampled($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
}else{
$dest = imagecreate($width, $height);
imagecopyresized($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
}
imagejpeg($dest, "../upload/goods/".$save_name, 90);
// png
}else if($timg[2] == 3){
$cfile = imagecreatefrompng($srcname);
if($gdver == 2){
$dest = imagecreatetruecolor($width, $height);
imagecopyresampled($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
}else{
$dest = imagecreate($width, $height);
imagecopyresized($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
}
imagepng($dest, "../upload/goods/".$save_name, 90);
// gif
}else if($timg[2] == 1){
$cfile = imagecreatefromgif($srcname);
if($gdver == 2){
$dest = imagecreatetruecolor($width, $height);
imagecopyresampled($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
}else{
$dest = imagecreate($width, $height);
imagecopyresized($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
}
imagegif($dest, "../upload/goods/".$save_name, 90);
}
// 메모리에 있는 그림 삭제
imagedestroy($dest);
return 1;
}
관리자님 g4도 탭 치환좀 해주십시오.
댓글 5개
atria
19년 전
이거 어디에 어떻게 쓰는거죠?
19년 전
사용이 간편하고 편리하겠네요.
설치해서 사용해 보겠습니다.
감사합니다.
설치해서 사용해 보겠습니다.
감사합니다.
그/누/보/드/4/T/I/P
19년 전
[GD] gif/jp(e)g/png 를 이용한 gd 버젼별 썸네일 생성
에스아이알에 sjsjin님이 올려주신 팁입니다.
[:SourceStart:]
[:BOX4:]
// 호출시
put_gdimage(\'원본파일명\', 생성가로, 생성세로, \'저장될파일명\');
// 정상생성여부 확인시 : 정상생성시 1을 리턴, 이외는 실패
// gd 이미지 생성
// $img_name …
에스아이알에 sjsjin님이 올려주신 팁입니다.
[:SourceStart:]
[:BOX4:]
// 호출시
put_gdimage(\'원본파일명\', 생성가로, 생성세로, \'저장될파일명\');
// 정상생성여부 확인시 : 정상생성시 1을 리턴, 이외는 실패
// gd 이미지 생성
// $img_name …
용된지렁이
19년 전
고맙게 사용하겠습니다^^
분홍타이거
18년 전
1
게시판 목록
그누4 팁자료실
그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.
나누면 즐거움이 커집니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 309 |
|
19년 전 | 7040 | |
| 308 | 19년 전 | 9445 | ||
| 307 |
해바라기군
|
19년 전 | 4044 | |
| 306 |
mando
|
19년 전 | 3208 | |
| 305 | 19년 전 | 6582 | ||
| 304 | 19년 전 | 3751 | ||
| 303 | 19년 전 | 4157 | ||
| 302 | 19년 전 | 16862 | ||
| 301 |
mando
|
19년 전 | 4067 | |
| 300 |
|
19년 전 | 32760 | |
| 299 | 19년 전 | 5113 | ||
| 298 |
네잎클로버
|
19년 전 | 6960 | |
| 297 |
niceview
|
19년 전 | 4313 | |
| 296 |
NeoGenesis
|
19년 전 | 3134 | |
| 295 | 19년 전 | 6058 | ||
| 294 | 19년 전 | 8998 | ||
| 293 | 19년 전 | 7759 | ||
| 292 | 19년 전 | 7165 | ||
| 291 |
네잎클로버
|
19년 전 | 2586 | |
| 290 |
shinwha
|
19년 전 | 5920 |
회원들의 홈페이지 뽑아 보여주기 [13]
mando
•
19년 전
전체 게시판의 링크 1과 글제목 다 뽑아 보기 [17]
mando
•
19년 전
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기