썸네일 생성시 갯수 지정하는 방법 알려주세요. 정보
썸네일 생성시 갯수 지정하는 방법 알려주세요.본문
이미지 게시판에 썸네일을 적용 하는데...
아래 소스를 보면 아시겠지만 총 3종류의 썸네일을 생성합니다.
가로 600의 썸네일은 화면에 다 보여야 되니까 아래처럼 하면 다 생성됩니다.
가로 240의 썸네일은 리스트에 사용해야 하니까 처음2개만 생성했으면 합니다.
그리고 가로 90의 썸네일은 최신글에 사용하려는데 처음 1개만 생성했으면 합니다.
아래 소스처럼 하면 파일갯수만큼 생성이 됩니다.
파일번호로 찍어서 생성하면 갯수를 조절이 가능하지만 문제는
파일0번부터 이미지가 아닐때도 있습니다.
파일3번이 첫번째 이미지일수도 있고 해서..
// 이미지 출력
if (!function_exists("imagecopyresampled")) alert("GD 2.0.1 이상 버전이 설치되어 있어야 사용할 수 있는 갤러리 게시판 입니다.");
if (!function_exists("imagecopyresampled")) alert("GD 2.0.1 이상 버전이 설치되어 있어야 사용할 수 있는 갤러리 게시판 입니다.");
$max_width = "600";
$meduim_width = "240";
$small_width = "20";
$quality = "90";
$meduim_width = "240";
$small_width = "20";
$quality = "90";
$data_path = $g4[path]."/data/file/$bo_table";
$thumb_path = $data_path.'/thumb';
$thumb_path = $data_path.'/thumb';
for ($i=0; $i<count($view[file]); $i++)
{
$thumb_img_l = $thumb_path.'/'.$wr_id.'_l'.$i;
$thumb_img_m = $thumb_path.'/'.$wr_id.'_m'.$i;
$thumb_img_s = $thumb_path.'/'.$wr_id.'_s'.$i;
{
$thumb_img_l = $thumb_path.'/'.$wr_id.'_l'.$i;
$thumb_img_m = $thumb_path.'/'.$wr_id.'_m'.$i;
$thumb_img_s = $thumb_path.'/'.$wr_id.'_s'.$i;
if (!file_exists($thumb_img_s))
{
$file = $data_path.'/'.$view[file][$i][file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file) && file_exists($file))
{
$size = getimagesize($file);
if ($size[0] > $small_width)
{
if ($size[2] == 1) $src = imagecreatefromgif($file);
else if ($size[2] == 2) $src = imagecreatefromjpeg($file);
else if ($size[2] == 3) $src = imagecreatefrompng($file);
else
break;
{
$file = $data_path.'/'.$view[file][$i][file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file) && file_exists($file))
{
$size = getimagesize($file);
if ($size[0] > $small_width)
{
if ($size[2] == 1) $src = imagecreatefromgif($file);
else if ($size[2] == 2) $src = imagecreatefromjpeg($file);
else if ($size[2] == 3) $src = imagecreatefrompng($file);
else
break;
$rate = $small_width / $size[0];
$height = (int)($size[1] * $rate);
$height = (int)($size[1] * $rate);
$dst = imagecreatetruecolor($small_width, $height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $small_width, $height, $size[0], $size[1]);
imagejpeg($dst, $thumb_img_s, $quality);
chmod($thumb_img_s, 0606);
} else {
@unlink($thumb_img_s);
}
}
}
imagecopyresampled($dst, $src, 0, 0, 0, 0, $small_width, $height, $size[0], $size[1]);
imagejpeg($dst, $thumb_img_s, $quality);
chmod($thumb_img_s, 0606);
} else {
@unlink($thumb_img_s);
}
}
}
if (!file_exists($thumb_img_m))
{
$file = $data_path.'/'.$view[file][$i][file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file) && file_exists($file))
{
$size = getimagesize($file);
if ($size[0] > $meduim_width)
{
if ($size[2] == 1) $src = imagecreatefromgif($file);
else if ($size[2] == 2) $src = imagecreatefromjpeg($file);
else if ($size[2] == 3) $src = imagecreatefrompng($file);
else
break;
{
$file = $data_path.'/'.$view[file][$i][file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file) && file_exists($file))
{
$size = getimagesize($file);
if ($size[0] > $meduim_width)
{
if ($size[2] == 1) $src = imagecreatefromgif($file);
else if ($size[2] == 2) $src = imagecreatefromjpeg($file);
else if ($size[2] == 3) $src = imagecreatefrompng($file);
else
break;
$rate = $meduim_width / $size[0];
$height = (int)($size[1] * $rate);
$height = (int)($size[1] * $rate);
$dst = imagecreatetruecolor($meduim_width, $height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $meduim_width, $height, $size[0], $size[1]);
imagejpeg($dst, $thumb_img_m, $quality);
chmod($thumb_img_m, 0606);
} else {
@unlink($thumb_img_m);
}
}
}
imagecopyresampled($dst, $src, 0, 0, 0, 0, $meduim_width, $height, $size[0], $size[1]);
imagejpeg($dst, $thumb_img_m, $quality);
chmod($thumb_img_m, 0606);
} else {
@unlink($thumb_img_m);
}
}
}
if (!file_exists($thumb_img_l))
{
$file = $data_path.'/'.$view[file][$i][file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file) && file_exists($file))
{
$size = getimagesize($file);
if ($size[0] > $max_width)
{
if ($size[2] == 1) $src = imagecreatefromgif($file);
else if ($size[2] == 2) $src = imagecreatefromjpeg($file);
else if ($size[2] == 3) $src = imagecreatefrompng($file);
else
break;
{
$file = $data_path.'/'.$view[file][$i][file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file) && file_exists($file))
{
$size = getimagesize($file);
if ($size[0] > $max_width)
{
if ($size[2] == 1) $src = imagecreatefromgif($file);
else if ($size[2] == 2) $src = imagecreatefromjpeg($file);
else if ($size[2] == 3) $src = imagecreatefrompng($file);
else
break;
$rate = $max_width / $size[0];
$height = (int)($size[1] * $rate);
$height = (int)($size[1] * $rate);
$dst = imagecreatetruecolor($max_width, $height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $max_width, $height, $size[0], $size[1]);
imagepng($dst, $thumb_img_l, $quality);
chmod($thumb_img_l, 0606);
} else {
@unlink($thumb_img_l);
}
}
}
imagecopyresampled($dst, $src, 0, 0, 0, 0, $max_width, $height, $size[0], $size[1]);
imagepng($dst, $thumb_img_l, $quality);
chmod($thumb_img_l, 0606);
} else {
@unlink($thumb_img_l);
}
}
}
}
댓글 전체

썸네일 생성하는 이 부분은 이대로 놔두시고
불러오는 쪽에서 조절하시면 됩니다.
skin/latest/basic.php를 보시면 최근글을 어떻게 불러오는지 나옵니다.
스킨게시판의 '최근게시물' 중 이미지 게시판 하나를 다운로드 하셔서 해보세요~
불러오는 쪽에서 조절하시면 됩니다.
skin/latest/basic.php를 보시면 최근글을 어떻게 불러오는지 나옵니다.
스킨게시판의 '최근게시물' 중 이미지 게시판 하나를 다운로드 하셔서 해보세요~
불러오기에서 문제가 되는게 아니고 필요없는 썸네일 용량이라도 줄여볼까 해서입니다.
스킨게시판에 있는 썸네일 생성 게시판은 하나같이 파일0만 생성해서...
if (($i==0)||($i==1)){ 이거면 될것 같기는 한데.. 소스가 지져분해질까봐...
암튼 관심 가져 주셔서 감사합니다.
스킨게시판에 있는 썸네일 생성 게시판은 하나같이 파일0만 생성해서...
if (($i==0)||($i==1)){ 이거면 될것 같기는 한데.. 소스가 지져분해질까봐...
암튼 관심 가져 주셔서 감사합니다.

앗.. 죄송합니다.
for ($i=0; $i<count($view[file]); $i++) 행을
if ( !isset($img_cnt) )
$img_cnt = count($view[file]);
for ($i=0; $i<img_cnt; $i++)
로 고쳐주신 다음에
불러오는 쪽에서 $img_cnt = 2; 이렇게 설정해 주시면 2개만 만들고
, 불러올 때 설정이 안되어 있으면 평소대로 동작합니다
for ($i=0; $i<count($view[file]); $i++) 행을
if ( !isset($img_cnt) )
$img_cnt = count($view[file]);
for ($i=0; $i<img_cnt; $i++)
로 고쳐주신 다음에
불러오는 쪽에서 $img_cnt = 2; 이렇게 설정해 주시면 2개만 만들고
, 불러올 때 설정이 안되어 있으면 평소대로 동작합니다
지금 적용시켜 봐야겠습니다. 답변 감사합니다.
별명이 바껴서 누구신가 했습니다. ^^;
좋은 밤 되세요.
별명이 바껴서 누구신가 했습니다. ^^;
좋은 밤 되세요.

헉 왜 아깐 안보이던게 지금 컴터 켜자마자 보이는거죠?
for문 안에 img_cnt앞에 $ 빼먹었어요.. -_-;
테스트 안해본게 들통났네요.. 미안합니다. ㅜ.-
for문 안에 img_cnt앞에 $ 빼먹었어요.. -_-;
테스트 안해본게 들통났네요.. 미안합니다. ㅜ.-
^^ 눈치로 알았었습니다.
해 봤습니다. 그런데 문제가 있어요. 저기서 count($view[file]) 이것이 갯수를 잡아주는게 아니고 번호를 매기는건가 봅니다.
그래서 문제가 뭐냐면 첫번째 파일0은 없고 파일1과 파일2이 있을 경우 $img_cnt=1 로 했을경우 없는 파일0을 1로 계산해서 썸네일이 생성이 안되는거였습니다. $img_cnt=2로 하면 파일1 하나만 썸네일을 생성합니다.
0이 없을경우 1이 생성되고 1이 없으면 2가 생성되고 이래야 하는데.. if else로는 엄두가 안나고 switch문은 아직 개념도 안 잡혀있어서... 첩첩산중입니다. ;;;
어쨌든 감사드립니다. (참, 별명 바꿨습니다.)
$thumb_img_s = $thumb_path.'/'.$wr_id.'_s'.$i;
$thumb_img_s = $thumb_path.'/'.$wr_id.'_s';
한개만 만드는 방법은 의외로 간단했습니다.
해 봤습니다. 그런데 문제가 있어요. 저기서 count($view[file]) 이것이 갯수를 잡아주는게 아니고 번호를 매기는건가 봅니다.
그래서 문제가 뭐냐면 첫번째 파일0은 없고 파일1과 파일2이 있을 경우 $img_cnt=1 로 했을경우 없는 파일0을 1로 계산해서 썸네일이 생성이 안되는거였습니다. $img_cnt=2로 하면 파일1 하나만 썸네일을 생성합니다.
0이 없을경우 1이 생성되고 1이 없으면 2가 생성되고 이래야 하는데.. if else로는 엄두가 안나고 switch문은 아직 개념도 안 잡혀있어서... 첩첩산중입니다. ;;;
어쨌든 감사드립니다. (참, 별명 바꿨습니다.)
$thumb_img_s = $thumb_path.'/'.$wr_id.'_s'.$i;
$thumb_img_s = $thumb_path.'/'.$wr_id.'_s';
한개만 만드는 방법은 의외로 간단했습니다.