리스트화면에서 2개이상의 썸네일을 생성하고자 할때... 정보
리스트화면에서 2개이상의 썸네일을 생성하고자 할때...본문
보드스킨의 리스트화면에서 하나의 게시물에 등록된 여러개의 이미지중에
첫번째, 두번째 등록이미지를 썸네일로 생성해서 list.skin.php 화면에 뿌려줍니다.
현재 아래 처럼 첫번째 썸네일을 생성하는 코드를 복사해서 붙여넣기하여 사용하는데요
이것을 for문형식 또는 기타 다른 방법으로 코드를 좀 줄여서 표현할수는 없을까요??
비슷한 내용을 코드만 불필요하게 늘려서 표현하는거 같아서요.
그리고... 다른 방법으로...
- 한 게시물당 등록된 이미지수가 많을경우, 원하는 이미지의 수만큼
- 임의의 변수값을 하나 만들어서 (아래 코드상단 참고) 지정된 그 값에 맞게
- 여러개의 썸네일을 생성할수 있는 방법은 없을지요.
도움글 좀 부탁드립니다. 관련 코드는 아래와 같습니다
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<?
//-------------------------------------------
// 한게시물당 생성되는 썸네일 갯수 지정
$thumb_list_count = '2'; // <----- 임의의 변수값지정 (현재 미사용)
//-------------------------------------------
// 썸네일 사이즈(가로|세로) 지정
list($thu_width, $thu_height) = explode("|", $board[bo_4]);
$thu_quality = '98'; //썸네일 퀄리티_100 이하
$data_path = $g4[path]."/data/file/$bo_table";
$thumb_path = $data_path.'/thumb';
@mkdir($thumb_path, 0707);
@chmod($thumb_path, 0707);
$mod = $board[bo_gallery_cols];
$td_width = (int)(100 / $mod);
?>
<?
for ($i=0; $i<count($list); $i++) {
if ($i && $i%$mod==0)
echo "</tr><td colspan='{$mod}' height=5></td></tr>";
$img_cnt = array() ;
for ($k=0,$img_num=0; $k<$list[$i][file][count]; $k++) {
if($list[$i][file][$k][file]) { //break;
$img_cnt[$img_num]=$list[$i][file][$k][file] ;
$img_num ++;
}
}
$max_img_cnt = count($img_cnt);
$image = $img_cnt[0];
$thumbnail_img = "<img src='$board_skin_path/img/no_image.gif' border=0 width='$thu_width' height='$thu_height' title='이미지 없음' style='border:0px solid #333333;'>";
$thumbnail_img2 = "<img src='$board_skin_path/img/no_image.gif' border=0 width='$thu_width' height='$thu_height' title='이미지 없음' style='border:0px solid #333333;'>";
$thumb = $thumb_path.'/'.$list[$i][file][0][file];
$thumb2 = $thumb_path.'/'.$list[$i][file][1][file];
if (!file_exists($thumb)) {
$file = $list[$i][file][0][path] .'/'. $list[$i][file][0][file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file) && file_exists($file)) {
$size = @getimagesize($file);
if ($size[2] == 1)
$src = imagecreatefromgif($file);
else if ($size[2] == 2)
$src = imagecreatefromjpeg($file);
else if ($size[2] == 3)
$src = imagecreatefrompng($file);
else
continue;
$rate = $thu_width / $size[0];
$height = (int)($size[1] * $rate);
if ($height < $thu_height)
$dst = imagecreatetruecolor($thu_width, $height);
else
$dst = imagecreatetruecolor($thu_width, $thu_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $thu_width, $height, $size[0], $size[1]);
imagejpeg($dst, $thumb_path.'/'.$list[$i][file][0][file], $thu_quality);
chmod($thumb_path.'/'.$list[$i][file][0][file], 0707);
}
}
if (file_exists($thumb)) {
$thumbnail_img = "<img src='$thumb' width='$thu_width' height='$thu_height' border=0 style='border:3px solid #333333;'>";
}
if (!file_exists($thumb2)) {
$file2 = $list[$i][file][1][path] .'/'. $list[$i][file][1][file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file2) && file_exists($file2)) {
$size = @getimagesize($file2);
if ($size[2] == 1)
$src = imagecreatefromgif($file2);
else if ($size[2] == 2)
$src = imagecreatefromjpeg($file2);
else if ($size[2] == 3)
$src = imagecreatefrompng($file2);
else
continue;
$rate = $thu_width / $size[0];
$height = (int)($size[1] * $rate);
if ($height < $thu_height)
$dst = imagecreatetruecolor($thu_width, $height);
else
$dst = imagecreatetruecolor($thu_width, $thu_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $thu_width, $height, $size[0], $size[1]);
imagejpeg($dst, $thumb_path.'/'.$list[$i][file][1][file], $thu_quality);
chmod($thumb_path.'/'.$list[$i][file][1][file], 0707);
}
}
if (file_exists($thumb2)) {
$thumbnail_img2 = "<img src='$thumb2' width='$thu_width' height='$thu_height' border=0 style='border:3px solid #333333;'>";
}
/* ---------------------- 옵션 ----------------------------------- */
$title = "테스트";
$file_cnt = $list[$i][file][count]; // 게시물당 등록된 파일갯수
if($file_cnt >=2) {$fcolor='#FF0000';}else{$fcolor='#888888';} // 등록파일이 두개이상인경우, 글자색상
$subject = $list[$i][subject];
//---- 이미지 새창보기 여부 설정
if($board[bo_3] == '1') { // 뷰화면에서 이미지보기
$view_img = "<a href='{$g4[bbs_path]}/board.php?bo_table=$bo_table&wr_id={$list[$i][wr_id]}&page=$page'>";
$view_href = "<a class='bl' href='{$g4[bbs_path]}/board.php?bo_table=$bo_table&wr_id={$list[$i][wr_id]}&page=$page'>";
}
if($board[bo_3] == '2') { // 리스트이미지:새창, 제목글:뷰화면
$view_img = "<a href=\"javascript:;\" OnClick=\"image_viewer('$g4[path]/data/file/$bo_table/$image')\" onFocus=\"this.blur();\">";
$view_href = "<a class='bl' href='{$g4[bbs_path]}/board.php?bo_table=$bo_table&wr_id={$list[$i][wr_id]}&page=$page'>";
}
if($board[bo_3] == '3') { // 모두 새창으로 보기
$view_img = "<a href=\"javascript:;\" OnClick=\"image_viewer('$g4[path]/data/file/$bo_table/$image')\" onFocus=\"this.blur();\">";
if($member[mb_level] <= 9) {
$view_href = "<a class='bl' href=\"javascript:;\" OnClick=\"image_viewer('$g4[path]/data/file/$bo_table/$image')\" onFocus=\"this.blur();\">";
}else {
$view_href = "<a class='bl' href='{$g4[bbs_path]}/board.php?bo_table=$bo_table&wr_id={$list[$i][wr_id]}&page=$page'>";
}
}
$checkbox = "";
if ($is_checkbox)
$checkbox = "<input type=checkbox name=chk_wr_id[] value='{$list[$i][wr_id]}'>";
$comment = " <a href=\"{$list[$i][comment_href]}\"><span style='font-size:8pt;'>{$list[$i][comment_cnt]}</span></a>";
/* ---------------------- 옵션 ----------------------------------- */
$style = "";
if ($list[$i][icon_new])
$style = " style='font-weight:bold;' ";
$subject = "<span $style>".$subject."</span>";
$comment_cnt = "";
if ($list[$i][comment_cnt])
$comment_cnt = " <a href=\"{$list[$i][comment_href]}\"><span style='font-size:8pt;color:#888888'>{$list[$i][comment_cnt]}</span></a>";
echo "<td width='{$td_width}%' align='center' valign=top style='padding-top:5px; word-break:break-all;'>\n";
/* ------ 이미지 정보출력 start --- */
echo "<div>";
echo "{$view_img}";
echo $thumbnail_img ." ". $thumbnail_img2 ;
echo "</a>";
echo "</div>";
echo "<div style='clear:both; text-align:center;'>";
echo "{$checkbox} {$view_href}";
echo "<span style='letter-spacing:-1px'>{$subject}</span></a> ";
echo $comment_cnt;
echo "</div>";
echo "<div>";
if($board[bo_3] !== '3') {
echo "<span style='font-family:gulim, AppleGothic, sans-serif; font-size:12px;letter-spacing:-1px;'><font color='{$fcolor}'>이미지수 : {$max_img_cnt}</font> <font color='#888888'>조회 : {$list[$i][wr_hit]}</font></span>";
}
echo "</div>";
/* ------ 이미지 정보출력 end --- */
echo "</td>\n";
}
// 나머지 td
$cnt = $i%$mod;
if ($cnt)
for ($i=$cnt; $i<$mod; $i++)
echo "<td width='{$td_width}%'> </td>";
?>
</tr>
<? if (count($list) == 0) { echo "<tr><td colspan='$mod' height=100 align=center>게시물이 없습니다.</td></tr>"; } ?>
</table>
첫번째, 두번째 등록이미지를 썸네일로 생성해서 list.skin.php 화면에 뿌려줍니다.
현재 아래 처럼 첫번째 썸네일을 생성하는 코드를 복사해서 붙여넣기하여 사용하는데요
이것을 for문형식 또는 기타 다른 방법으로 코드를 좀 줄여서 표현할수는 없을까요??
비슷한 내용을 코드만 불필요하게 늘려서 표현하는거 같아서요.
그리고... 다른 방법으로...
- 한 게시물당 등록된 이미지수가 많을경우, 원하는 이미지의 수만큼
- 임의의 변수값을 하나 만들어서 (아래 코드상단 참고) 지정된 그 값에 맞게
- 여러개의 썸네일을 생성할수 있는 방법은 없을지요.
도움글 좀 부탁드립니다. 관련 코드는 아래와 같습니다
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<?
//-------------------------------------------
// 한게시물당 생성되는 썸네일 갯수 지정
$thumb_list_count = '2'; // <----- 임의의 변수값지정 (현재 미사용)
//-------------------------------------------
// 썸네일 사이즈(가로|세로) 지정
list($thu_width, $thu_height) = explode("|", $board[bo_4]);
$thu_quality = '98'; //썸네일 퀄리티_100 이하
$data_path = $g4[path]."/data/file/$bo_table";
$thumb_path = $data_path.'/thumb';
@mkdir($thumb_path, 0707);
@chmod($thumb_path, 0707);
$mod = $board[bo_gallery_cols];
$td_width = (int)(100 / $mod);
?>
<?
for ($i=0; $i<count($list); $i++) {
if ($i && $i%$mod==0)
echo "</tr><td colspan='{$mod}' height=5></td></tr>";
$img_cnt = array() ;
for ($k=0,$img_num=0; $k<$list[$i][file][count]; $k++) {
if($list[$i][file][$k][file]) { //break;
$img_cnt[$img_num]=$list[$i][file][$k][file] ;
$img_num ++;
}
}
$max_img_cnt = count($img_cnt);
$image = $img_cnt[0];
$thumbnail_img = "<img src='$board_skin_path/img/no_image.gif' border=0 width='$thu_width' height='$thu_height' title='이미지 없음' style='border:0px solid #333333;'>";
$thumbnail_img2 = "<img src='$board_skin_path/img/no_image.gif' border=0 width='$thu_width' height='$thu_height' title='이미지 없음' style='border:0px solid #333333;'>";
$thumb = $thumb_path.'/'.$list[$i][file][0][file];
$thumb2 = $thumb_path.'/'.$list[$i][file][1][file];
if (!file_exists($thumb)) {
$file = $list[$i][file][0][path] .'/'. $list[$i][file][0][file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file) && file_exists($file)) {
$size = @getimagesize($file);
if ($size[2] == 1)
$src = imagecreatefromgif($file);
else if ($size[2] == 2)
$src = imagecreatefromjpeg($file);
else if ($size[2] == 3)
$src = imagecreatefrompng($file);
else
continue;
$rate = $thu_width / $size[0];
$height = (int)($size[1] * $rate);
if ($height < $thu_height)
$dst = imagecreatetruecolor($thu_width, $height);
else
$dst = imagecreatetruecolor($thu_width, $thu_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $thu_width, $height, $size[0], $size[1]);
imagejpeg($dst, $thumb_path.'/'.$list[$i][file][0][file], $thu_quality);
chmod($thumb_path.'/'.$list[$i][file][0][file], 0707);
}
}
if (file_exists($thumb)) {
$thumbnail_img = "<img src='$thumb' width='$thu_width' height='$thu_height' border=0 style='border:3px solid #333333;'>";
}
if (!file_exists($thumb2)) {
$file2 = $list[$i][file][1][path] .'/'. $list[$i][file][1][file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file2) && file_exists($file2)) {
$size = @getimagesize($file2);
if ($size[2] == 1)
$src = imagecreatefromgif($file2);
else if ($size[2] == 2)
$src = imagecreatefromjpeg($file2);
else if ($size[2] == 3)
$src = imagecreatefrompng($file2);
else
continue;
$rate = $thu_width / $size[0];
$height = (int)($size[1] * $rate);
if ($height < $thu_height)
$dst = imagecreatetruecolor($thu_width, $height);
else
$dst = imagecreatetruecolor($thu_width, $thu_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $thu_width, $height, $size[0], $size[1]);
imagejpeg($dst, $thumb_path.'/'.$list[$i][file][1][file], $thu_quality);
chmod($thumb_path.'/'.$list[$i][file][1][file], 0707);
}
}
if (file_exists($thumb2)) {
$thumbnail_img2 = "<img src='$thumb2' width='$thu_width' height='$thu_height' border=0 style='border:3px solid #333333;'>";
}
/* ---------------------- 옵션 ----------------------------------- */
$title = "테스트";
$file_cnt = $list[$i][file][count]; // 게시물당 등록된 파일갯수
if($file_cnt >=2) {$fcolor='#FF0000';}else{$fcolor='#888888';} // 등록파일이 두개이상인경우, 글자색상
$subject = $list[$i][subject];
//---- 이미지 새창보기 여부 설정
if($board[bo_3] == '1') { // 뷰화면에서 이미지보기
$view_img = "<a href='{$g4[bbs_path]}/board.php?bo_table=$bo_table&wr_id={$list[$i][wr_id]}&page=$page'>";
$view_href = "<a class='bl' href='{$g4[bbs_path]}/board.php?bo_table=$bo_table&wr_id={$list[$i][wr_id]}&page=$page'>";
}
if($board[bo_3] == '2') { // 리스트이미지:새창, 제목글:뷰화면
$view_img = "<a href=\"javascript:;\" OnClick=\"image_viewer('$g4[path]/data/file/$bo_table/$image')\" onFocus=\"this.blur();\">";
$view_href = "<a class='bl' href='{$g4[bbs_path]}/board.php?bo_table=$bo_table&wr_id={$list[$i][wr_id]}&page=$page'>";
}
if($board[bo_3] == '3') { // 모두 새창으로 보기
$view_img = "<a href=\"javascript:;\" OnClick=\"image_viewer('$g4[path]/data/file/$bo_table/$image')\" onFocus=\"this.blur();\">";
if($member[mb_level] <= 9) {
$view_href = "<a class='bl' href=\"javascript:;\" OnClick=\"image_viewer('$g4[path]/data/file/$bo_table/$image')\" onFocus=\"this.blur();\">";
}else {
$view_href = "<a class='bl' href='{$g4[bbs_path]}/board.php?bo_table=$bo_table&wr_id={$list[$i][wr_id]}&page=$page'>";
}
}
$checkbox = "";
if ($is_checkbox)
$checkbox = "<input type=checkbox name=chk_wr_id[] value='{$list[$i][wr_id]}'>";
$comment = " <a href=\"{$list[$i][comment_href]}\"><span style='font-size:8pt;'>{$list[$i][comment_cnt]}</span></a>";
/* ---------------------- 옵션 ----------------------------------- */
$style = "";
if ($list[$i][icon_new])
$style = " style='font-weight:bold;' ";
$subject = "<span $style>".$subject."</span>";
$comment_cnt = "";
if ($list[$i][comment_cnt])
$comment_cnt = " <a href=\"{$list[$i][comment_href]}\"><span style='font-size:8pt;color:#888888'>{$list[$i][comment_cnt]}</span></a>";
echo "<td width='{$td_width}%' align='center' valign=top style='padding-top:5px; word-break:break-all;'>\n";
/* ------ 이미지 정보출력 start --- */
echo "<div>";
echo "{$view_img}";
echo $thumbnail_img ." ". $thumbnail_img2 ;
echo "</a>";
echo "</div>";
echo "<div style='clear:both; text-align:center;'>";
echo "{$checkbox} {$view_href}";
echo "<span style='letter-spacing:-1px'>{$subject}</span></a> ";
echo $comment_cnt;
echo "</div>";
echo "<div>";
if($board[bo_3] !== '3') {
echo "<span style='font-family:gulim, AppleGothic, sans-serif; font-size:12px;letter-spacing:-1px;'><font color='{$fcolor}'>이미지수 : {$max_img_cnt}</font> <font color='#888888'>조회 : {$list[$i][wr_hit]}</font></span>";
}
echo "</div>";
/* ------ 이미지 정보출력 end --- */
echo "</td>\n";
}
// 나머지 td
$cnt = $i%$mod;
if ($cnt)
for ($i=$cnt; $i<$mod; $i++)
echo "<td width='{$td_width}%'> </td>";
?>
</tr>
<? if (count($list) == 0) { echo "<tr><td colspan='$mod' height=100 align=center>게시물이 없습니다.</td></tr>"; } ?>
</table>
댓글 전체
썸네일 만드는 for문에서 $k<$list[$i][file][count]; <--이건 등록하는 모든 이미지를 썸네일로 만들겠지요
그러니 $k<$thumb_list_count; 이렇게만 바꿔주면 됩니다
그러니 $k<$thumb_list_count; 이렇게만 바꿔주면 됩니다
안녕하십니까...오랜만에 뵙는거 같군요 ^^;;
우선 댓글주셔서 감사합니다.
제가 잘 이해를 못하는것인지도 모르겠지만, ^^;;
언급해주신 for문은 썸네일을 만들어저주지는 못하고 전체 등록파일의 갯수만을 가져오고 있습니다
섬네일이 만들어지는 부분은... 아래부분입니다
----------------------------------------------------------
$thumbnail_img = "<img src='$board_skin_path/img/no_image.gif' border=0 width='$thu_width' height='$thu_height' title='이미지 없음' style='border:0px solid #333333;'>";
$thumbnail_img2 = "<img src='$board_skin_path/img/no_image.gif' border=0 width='$thu_width' height='$thu_height' title='이미지 없음' style='border:0px solid #333333;'>";
$thumb = $thumb_path.'/'.$list[$i][file][0][file];
$thumb2 = $thumb_path.'/'.$list[$i][file][1][file];
if (!file_exists($thumb)) {
$file = $list[$i][file][0][path] .'/'. $list[$i][file][0][file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file) && file_exists($file)) {
$size = @getimagesize($file);
if ($size[2] == 1)
$src = imagecreatefromgif($file);
else if ($size[2] == 2)
$src = imagecreatefromjpeg($file);
else if ($size[2] == 3)
$src = imagecreatefrompng($file);
else
continue;
$rate = $thu_width / $size[0];
$height = (int)($size[1] * $rate);
if ($height < $thu_height)
$dst = imagecreatetruecolor($thu_width, $height);
else
$dst = imagecreatetruecolor($thu_width, $thu_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $thu_width, $height, $size[0], $size[1]);
imagejpeg($dst, $thumb_path.'/'.$list[$i][file][0][file], $thu_quality);
chmod($thumb_path.'/'.$list[$i][file][0][file], 0707);
}
}
if (file_exists($thumb)) {
$thumbnail_img = "<img src='$thumb' width='$thu_width' height='$thu_height' border=0 style='border:3px solid #333333;'>";
}
if (!file_exists($thumb2)) {
$file2 = $list[$i][file][1][path] .'/'. $list[$i][file][1][file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file2) && file_exists($file2)) {
$size = @getimagesize($file2);
if ($size[2] == 1)
$src = imagecreatefromgif($file2);
else if ($size[2] == 2)
$src = imagecreatefromjpeg($file2);
else if ($size[2] == 3)
$src = imagecreatefrompng($file2);
else
continue;
$rate = $thu_width / $size[0];
$height = (int)($size[1] * $rate);
if ($height < $thu_height)
$dst = imagecreatetruecolor($thu_width, $height);
else
$dst = imagecreatetruecolor($thu_width, $thu_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $thu_width, $height, $size[0], $size[1]);
imagejpeg($dst, $thumb_path.'/'.$list[$i][file][1][file], $thu_quality);
chmod($thumb_path.'/'.$list[$i][file][1][file], 0707);
}
}
if (file_exists($thumb2)) {
$thumbnail_img2 = "<img src='$thumb2' width='$thu_width' height='$thu_height' border=0 style='border:3px solid #333333;'>";
}
-----------------------------------------------------------
위 코드는 현재 2개의 썸네일을 만드는 형식인데 어차피 거의 동일한 내용이라서
좀더 간단히 코드를 줄이는 방법에 대한 문의가 1차적인것이고
좀더 나아가서...
한 게시물에 여러개의 이미지를 등록시, 임의의 변수를 설정해서
게시물에 등록된 이미지를 임의의 변수값만큼 썸네일을 만들수있는 형태를 구현해보고자 하는것입니다
원래의 썸네일 생성코드는 .. $list[$i][wr_id] ..값으로 만들었는데
게시물에 두개이상의 썸네일을 만드는 작업을 하려니, wr_id값으로는 생성이 힘들어서
jpg원본을 복사하여 썸네일로 줄여서 만드는 방법을 채택해본겁니다.
문제는.... 위 질의한 내용과 연관되는 다음의 문제가....
위 코드로 생성된 2개의 썸네일 코드로는
게시물의 원본이미지를 수정/삭제시 썸네일이 변경/삭제가 안되고 계속 만들어져서 쌓이는 문제와
이미지가 없는경우, 보여줘야할 no_image.gif 를 불러오지 못하는 문제...등
며칠째 풀리지가 않습니다.
혹...다시 보시면 도움좀 부탁드리겠습니다 ^^;;
우선 댓글주셔서 감사합니다.
제가 잘 이해를 못하는것인지도 모르겠지만, ^^;;
언급해주신 for문은 썸네일을 만들어저주지는 못하고 전체 등록파일의 갯수만을 가져오고 있습니다
섬네일이 만들어지는 부분은... 아래부분입니다
----------------------------------------------------------
$thumbnail_img = "<img src='$board_skin_path/img/no_image.gif' border=0 width='$thu_width' height='$thu_height' title='이미지 없음' style='border:0px solid #333333;'>";
$thumbnail_img2 = "<img src='$board_skin_path/img/no_image.gif' border=0 width='$thu_width' height='$thu_height' title='이미지 없음' style='border:0px solid #333333;'>";
$thumb = $thumb_path.'/'.$list[$i][file][0][file];
$thumb2 = $thumb_path.'/'.$list[$i][file][1][file];
if (!file_exists($thumb)) {
$file = $list[$i][file][0][path] .'/'. $list[$i][file][0][file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file) && file_exists($file)) {
$size = @getimagesize($file);
if ($size[2] == 1)
$src = imagecreatefromgif($file);
else if ($size[2] == 2)
$src = imagecreatefromjpeg($file);
else if ($size[2] == 3)
$src = imagecreatefrompng($file);
else
continue;
$rate = $thu_width / $size[0];
$height = (int)($size[1] * $rate);
if ($height < $thu_height)
$dst = imagecreatetruecolor($thu_width, $height);
else
$dst = imagecreatetruecolor($thu_width, $thu_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $thu_width, $height, $size[0], $size[1]);
imagejpeg($dst, $thumb_path.'/'.$list[$i][file][0][file], $thu_quality);
chmod($thumb_path.'/'.$list[$i][file][0][file], 0707);
}
}
if (file_exists($thumb)) {
$thumbnail_img = "<img src='$thumb' width='$thu_width' height='$thu_height' border=0 style='border:3px solid #333333;'>";
}
if (!file_exists($thumb2)) {
$file2 = $list[$i][file][1][path] .'/'. $list[$i][file][1][file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file2) && file_exists($file2)) {
$size = @getimagesize($file2);
if ($size[2] == 1)
$src = imagecreatefromgif($file2);
else if ($size[2] == 2)
$src = imagecreatefromjpeg($file2);
else if ($size[2] == 3)
$src = imagecreatefrompng($file2);
else
continue;
$rate = $thu_width / $size[0];
$height = (int)($size[1] * $rate);
if ($height < $thu_height)
$dst = imagecreatetruecolor($thu_width, $height);
else
$dst = imagecreatetruecolor($thu_width, $thu_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $thu_width, $height, $size[0], $size[1]);
imagejpeg($dst, $thumb_path.'/'.$list[$i][file][1][file], $thu_quality);
chmod($thumb_path.'/'.$list[$i][file][1][file], 0707);
}
}
if (file_exists($thumb2)) {
$thumbnail_img2 = "<img src='$thumb2' width='$thu_width' height='$thu_height' border=0 style='border:3px solid #333333;'>";
}
-----------------------------------------------------------
위 코드는 현재 2개의 썸네일을 만드는 형식인데 어차피 거의 동일한 내용이라서
좀더 간단히 코드를 줄이는 방법에 대한 문의가 1차적인것이고
좀더 나아가서...
한 게시물에 여러개의 이미지를 등록시, 임의의 변수를 설정해서
게시물에 등록된 이미지를 임의의 변수값만큼 썸네일을 만들수있는 형태를 구현해보고자 하는것입니다
원래의 썸네일 생성코드는 .. $list[$i][wr_id] ..값으로 만들었는데
게시물에 두개이상의 썸네일을 만드는 작업을 하려니, wr_id값으로는 생성이 힘들어서
jpg원본을 복사하여 썸네일로 줄여서 만드는 방법을 채택해본겁니다.
문제는.... 위 질의한 내용과 연관되는 다음의 문제가....
위 코드로 생성된 2개의 썸네일 코드로는
게시물의 원본이미지를 수정/삭제시 썸네일이 변경/삭제가 안되고 계속 만들어져서 쌓이는 문제와
이미지가 없는경우, 보여줘야할 no_image.gif 를 불러오지 못하는 문제...등
며칠째 풀리지가 않습니다.
혹...다시 보시면 도움좀 부탁드리겠습니다 ^^;;