cheditor의 업로드 기능을 이용한 첨부이미지를썸네일로 생성
링크
http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=45445&page=2 (535) http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=24485 (701)
어찌 하다보니 만들게 되었습니다. -_-;;
여전히 짜집기입니다.
- 제약사항 -
1. 그누보드는 루트 폴더 바로 아래 설치되어 있어야 됩니다.
예 : http://myhome.com/gnu
2. cheditor를 이용한 위지웍에디트 모드에서 cheditor에 자체 내장된 이미지 업로드기능을 이용한
이미지에만 적용됩니다.
3. 첫번째 이미지는 반드시 cheditor로 올린것이어야 됩니다.
4. 첫번째 이미지만 썸네일로 생성됩니다.
wr_content에서 img 테그에서 순서대로 파일을 뽑아오기 때문에
첫부분에 다른 서버에 파일을 링크하면 안됩니다.
/** 썸네일 함수
$file : 원본이미지 파일
$save_filename : 저장할 파일명
$save_path : 저장할 경로
$max_width : 만들이미지의 width 값
$max_height : 만들이미지의 height 값
*/
function thumimg($file, $save_filename, $save_path, $max_width, $max_height)
{
$img_info = getImageSize($file);
if($img_info[2] == 1)
{
$src_img = ImageCreateFromGif($file);
}elseif($img_info[2] == 2){
$src_img = ImageCreateFromJPEG($file);
}elseif($img_info[2] == 3){
$src_img = ImageCreateFromPNG($file);
}else{
return 0;
}
$img_width = $img_info[0];
$img_height = $img_info[1];
if($img_width > $max_width || $img_height > $max_height)
{
if($img_width == $img_height)
{
$dst_width = $max_width;
$dst_height = $max_height;
}elseif($img_width > $img_height){
$dst_width = $max_width;
$dst_height = $max_height;
// $dst_height = ceil(($max_width / $img_width) * $img_height);
}else{
$dst_height = $max_height;
$dst_height = $max_height;
// $dst_width = ceil(($max_height / $img_height) * $img_width);
}
}else{
$dst_width = $img_width;
$dst_height = $img_height;
}
if($dst_width < $max_width) $srcx = ceil(($max_width - $dst_width)/2); else $srcx = 0;
if($dst_height < $max_height) $srcy = ceil(($max_height - $dst_height)/2); else $srcy = 0;
if($img_info[2] == 1)
{
$dst_img = imagecreate($max_width, $max_height);
}else{
$dst_img = imagecreatetruecolor($max_width, $max_height);
}
$bgc = ImageColorAllocate($dst_img, 255, 255, 255);
ImageFilledRectangle($dst_img, 0, 0, $max_width, $max_height, $bgc);
ImageCopyResampled($dst_img, $src_img, $srcx, $srcy, 0, 0, $dst_width, $dst_height, ImageSX($src_img),ImageSY($src_img));
if($img_info[2] == 1)
{
ImageInterlace($dst_img);
ImageGif($dst_img, $save_path.$save_filename);
}elseif($img_info[2] == 2){
ImageInterlace($dst_img);
ImageJPEG($dst_img, $save_path.$save_filename);
}elseif($img_info[2] == 3){
ImagePNG($dst_img, $save_path.$save_filename);
}
ImageDestroy($dst_img);
ImageDestroy($src_img);
}
// 썸네일 함수끝
function extract_img($src) {
$re = '/src[ =]+[\'"]([^\'"]+\.(?:gif|jpg|png|bmp))[\'"]/i';
preg_match_all($re, $src, &$match, PREG_PATTERN_ORDER);
return $match[1];
}
// 아래 g4_write_에 게시판 id를 입력해주세요
//예) g4_write_gallery
$sql="select * from g4_write_게시판ID입력 order by wr_datetime DESC limit 4";
$result=mysql_query($sql);
for($i=0; $data=mysql_fetch_array($result); $i++){
$imgs[$i] = extract_img($data[wr_content]);
}
$total = count($imgs);
for($i=0 ; $total>$i; $i++){
$fullpath = explode("/", $imgs[$i][0]);
$url = "http://".$fullpath[2]."/".$fullpath[3];
$ch_img = str_replace("$url","", $imgs[$i][0]);
$file=$g4[path].$ch_img;
$filename=count($fullpath) - 1;
$save_filename = $fullpath[$filename].".thum";
$save_path =str_replace("$fullpath[$filename]","",$file);
$max_width ="80";
$max_height ="60";
//echo $file."->대상파일<BR>";
//echo $save_filename."->저장될파일명<BR>";
//echo $save_path."->저장될경로명<BR>";
if(!file_exists($save_filename)){
thumimg($file, $save_filename, $save_path, $max_width, $max_height);
}
echo "<img src='$file.thum'><br>";
}
여전히 짜집기입니다.
- 제약사항 -
1. 그누보드는 루트 폴더 바로 아래 설치되어 있어야 됩니다.
예 : http://myhome.com/gnu
2. cheditor를 이용한 위지웍에디트 모드에서 cheditor에 자체 내장된 이미지 업로드기능을 이용한
이미지에만 적용됩니다.
3. 첫번째 이미지는 반드시 cheditor로 올린것이어야 됩니다.
4. 첫번째 이미지만 썸네일로 생성됩니다.
wr_content에서 img 테그에서 순서대로 파일을 뽑아오기 때문에
첫부분에 다른 서버에 파일을 링크하면 안됩니다.
/** 썸네일 함수
$file : 원본이미지 파일
$save_filename : 저장할 파일명
$save_path : 저장할 경로
$max_width : 만들이미지의 width 값
$max_height : 만들이미지의 height 값
*/
function thumimg($file, $save_filename, $save_path, $max_width, $max_height)
{
$img_info = getImageSize($file);
if($img_info[2] == 1)
{
$src_img = ImageCreateFromGif($file);
}elseif($img_info[2] == 2){
$src_img = ImageCreateFromJPEG($file);
}elseif($img_info[2] == 3){
$src_img = ImageCreateFromPNG($file);
}else{
return 0;
}
$img_width = $img_info[0];
$img_height = $img_info[1];
if($img_width > $max_width || $img_height > $max_height)
{
if($img_width == $img_height)
{
$dst_width = $max_width;
$dst_height = $max_height;
}elseif($img_width > $img_height){
$dst_width = $max_width;
$dst_height = $max_height;
// $dst_height = ceil(($max_width / $img_width) * $img_height);
}else{
$dst_height = $max_height;
$dst_height = $max_height;
// $dst_width = ceil(($max_height / $img_height) * $img_width);
}
}else{
$dst_width = $img_width;
$dst_height = $img_height;
}
if($dst_width < $max_width) $srcx = ceil(($max_width - $dst_width)/2); else $srcx = 0;
if($dst_height < $max_height) $srcy = ceil(($max_height - $dst_height)/2); else $srcy = 0;
if($img_info[2] == 1)
{
$dst_img = imagecreate($max_width, $max_height);
}else{
$dst_img = imagecreatetruecolor($max_width, $max_height);
}
$bgc = ImageColorAllocate($dst_img, 255, 255, 255);
ImageFilledRectangle($dst_img, 0, 0, $max_width, $max_height, $bgc);
ImageCopyResampled($dst_img, $src_img, $srcx, $srcy, 0, 0, $dst_width, $dst_height, ImageSX($src_img),ImageSY($src_img));
if($img_info[2] == 1)
{
ImageInterlace($dst_img);
ImageGif($dst_img, $save_path.$save_filename);
}elseif($img_info[2] == 2){
ImageInterlace($dst_img);
ImageJPEG($dst_img, $save_path.$save_filename);
}elseif($img_info[2] == 3){
ImagePNG($dst_img, $save_path.$save_filename);
}
ImageDestroy($dst_img);
ImageDestroy($src_img);
}
// 썸네일 함수끝
function extract_img($src) {
$re = '/src[ =]+[\'"]([^\'"]+\.(?:gif|jpg|png|bmp))[\'"]/i';
preg_match_all($re, $src, &$match, PREG_PATTERN_ORDER);
return $match[1];
}
// 아래 g4_write_에 게시판 id를 입력해주세요
//예) g4_write_gallery
$sql="select * from g4_write_게시판ID입력 order by wr_datetime DESC limit 4";
$result=mysql_query($sql);
for($i=0; $data=mysql_fetch_array($result); $i++){
$imgs[$i] = extract_img($data[wr_content]);
}
$total = count($imgs);
for($i=0 ; $total>$i; $i++){
$fullpath = explode("/", $imgs[$i][0]);
$url = "http://".$fullpath[2]."/".$fullpath[3];
$ch_img = str_replace("$url","", $imgs[$i][0]);
$file=$g4[path].$ch_img;
$filename=count($fullpath) - 1;
$save_filename = $fullpath[$filename].".thum";
$save_path =str_replace("$fullpath[$filename]","",$file);
$max_width ="80";
$max_height ="60";
//echo $file."->대상파일<BR>";
//echo $save_filename."->저장될파일명<BR>";
//echo $save_path."->저장될경로명<BR>";
if(!file_exists($save_filename)){
thumimg($file, $save_filename, $save_path, $max_width, $max_height);
}
echo "<img src='$file.thum'><br>";
}
댓글 6개
19년 전
고생하셨습니다.
18년 전
수고하셨습니다. 이제서야 이걸 보다니....ㅠ.ㅠ
18년 전
좋은자료 감솨
18년 전
..
다스베이더
18년 전
감사합니다^_^
5년 전
이렇게 하면 에디터 내용html에 사이즈가 줄어든 이미지가 보여지는건가요?
게시판 목록
그누4 팁자료실
그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.
나누면 즐거움이 커집니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 3309 | 3년 전 | 1803 | ||
| 3308 | 11년 전 | 2091 | ||
| 3307 |
uPAmJ903
|
6년 전 | 4750 | |
| 3306 |
바른사나이
|
6년 전 | 3273 | |
| 3305 | 6년 전 | 12305 | ||
| 3304 | 7년 전 | 3702 | ||
| 3303 | 7년 전 | 3742 | ||
| 3302 |
지리산초보
|
7년 전 | 13596 | |
| 3301 |
sozet
|
8년 전 | 4901 | |
| 3300 |
sozet
|
8년 전 | 5971 | |
| 3299 |
sozet
|
8년 전 | 10862 | |
| 3298 | 8년 전 | 4015 | ||
| 3297 |
또치하우스
|
8년 전 | 4442 | |
| 3296 | 8년 전 | 11969 | ||
| 3295 |
또치하우스
|
8년 전 | 14985 | |
| 3294 | 8년 전 | 6024 | ||
| 3293 | 8년 전 | 5587 | ||
| 3292 |
|
9년 전 | 5316 | |
| 3291 | 9년 전 | 13677 | ||
| 3290 | 9년 전 | 5051 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기