이미지 업로드시 썸네일 변환하지 않고 원본 이미지 사용

이미지 업로드시 썸네일 변환하지 않고 원본 이미지 사용

QA

이미지 업로드시 썸네일 변환하지 않고 원본 이미지 사용

본문

아래 php파일은 게시판에서 이미지 업로드 시에 이미지를 썸네일로 변환하여 생성 후 외부에서 이미지가 썸네일로 보여지게끔 해주는 구문입니다.

 

그런데 썸네일 화질이 않좋아서 이 구문을 사용하지 않고 그냥 원본 파일이 보여지게끔하고 싶습니다.

 

전부다 지워버리니 아예 액박이 뜨거나 안나오더군요ㅜ
 

무엇을 어떻게 수정하면 좋을지 한번 봐주시길 부탁드립니다...!!

 


<?
//2011 / 11 / 02 : 장대혁
//-------------------------------------
$w = 236;  //변경 너비
$h = 154;  //변경 높이
$path = "$g4[path]/data/file/$bo_table/"; //경로명
//-------------------------------------
//--------------------------------------
//현재 등록되어 있는 이미지를 삭제한다
$result = mysql_query("select wr_10 from $write_table where wr_id='{$wr_id}'");
if(mysql_num_rows($result)){
 $row = mysql_fetch_array($result);
 if($row[wr_10] && file_exists($path.$row[wr_10])) {
  @unlink($path.$row[wr_10]);
 }
}
//--------------------------------------
//내용을 찾는다
$result = mysql_query("select bf_file from $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no limit 1");
if(mysql_num_rows($result))
{
 $row = mysql_fetch_array($result);
 $source_f = $row[bf_file];
 $change_f = "sumnail_{$bo_table}_{$wr_id}";
 //이미지 생성 (패스명 ,  소스 이미지명 , 변경 이름 , 변경높이 , 변경길이)
 $return_val = img_resizer( $path , $source_f , $change_f ,  $w , $h ); 
 if($return_val){
  mysql_query("update $write_table set wr_10 = '{$return_val}' where wr_id='{$wr_id}'");
 }
}
?>

<?
//----------------------------------------------
//이미지 사이즈 조정 함수
function img_resizer( $path , $source_f , $change_f ,  $w , $h ) 
{
 $image_type_arr = array(1=>"gif" , 2=>"jpg" , 3=> "png");
 //소스이미지가 존재하는지 확인
 $source_file = $path.$source_f;
 if( !$source_f || !file_exists($source_file) ){ return ""; }
 //--------------------------------
 $h=intval($h);       //변경높이
 $w=intval($w);       //변경너비
 $timg = @getimagesize($source_file);
 $width = $timg[0];
 $height = $timg[1];
 $change_w = intval($width);   //실변경너비 
 $change_h = intval($height);   //실변경높이
 
 
 //원본 이미지의 비유을 유지 하면 줄인다
 //$cmode -> true : 넓이 기준 , false : 높이 기준
 if( !$h ){$cmode = true;}              //너비만 상관있다
 else if( !$w){$cmode = false;}            //길이에만집중한다
 else if( $width  > ( ( $w / $h ) * $height ) ) {$cmode = true;}   //정상적인 비율로 줄인다 
 else {$cmode = false;}              //나머지를 정의한다     
 
 if($cmode) {
  if($width > $w ) {
   $change_w = $w ; 
   $change_h = $height * ( $change_w / $width) ; 
  }
 }
 else {
  if($height > $h ) {
   $change_h = $h ; 
   $change_w = $width * ( $change_h / $height) ; 
  }
 }
 //-------------------------------------
 $change_h = intval($change_h);
 $change_w = intval($change_w);
   
 /**************************************************************************/
 //이미지 형식 정의
 $e = $image_type_arr[$timg[2]];
 if(!$e){$e=strtolower(substr($source_f,strrpos($src,".")+1)); }
 
 //이미지를 변경한다 
 $r=1;   //정상변경 
 $image_p = imagecreatetruecolor($change_w , $change_h)   or $r=0 ;
 
 //변경파일이름정의
 $next_str = substr($source_f , strrpos($source_f,".")) ;
 $dst_name = $change_f.$next_str ;
 $dst_file = $path.$dst_name ;
 
 //------------------------------------
 //이미지 변경
 if($r) {
  if ($e == "jpg" ) { 
   $image = ImageCreateFromJpeg($source_file) or $r=0;
   imagecopyresampled($image_p, $image, 0, 0, 0, 0, $change_w , $change_h , $width, $height) or $r = 0 ;
   imagejpeg($image_p, $dst_file ) or $r = 0 ;
  }
  elseif ($e == "gif") { 
   $image = imagecreatefromgif($source_file)  ; 
   imagecopyresampled($image_p ,  $image , 0, 0, 0, 0, $change_w , $change_h , $width, $height) or $r = 0 ;
   imagegif($image_p, $dst_file ) or $r = 0 ;
  } 
  elseif ($e == "png") { 
   $image = ImageCreateFromPng($source_file) or $r=0; 
   imagecopyresampled($image_p, $image, 0, 0, 0, 0, $change_w , $change_h , $width, $height) or $r = 0 ;
   imagepng($image_p, $dst_file ) or $r = 0 ;
  } 
  elseif ($e == "bmp" || $e == "wbmp")  { 
   $image = ImageCreateFromwbmp($source_file) or $r=0; 
   imagecopyresampled($image_p, $image, 0, 0, 0, 0, $change_w , $change_h , $width, $height) or $r = 0 ;
   imagewbmp($image_p, $dst_file ) or $r = 0 ;
  } 
  else { 
     $r=0; 
  }
  imagedestroy($image_p);
    }
 if($r) { 
  chmod($dst_file , 0606);
  imagedestroy($image);
  if($dst_name && file_exists($dst_file)) { return $dst_name; }
  else{ $r = 0 ; }
 } 
 return $r; 
} 
?>
 

이 질문에 댓글 쓰기 :

답변 1

썸네일 만드는걸 지우시면 리스트같이 외부에 작게 표출할때도 원본파일을 사용해서 사용자가 불편할텐데요... 이렇게 되시면 썸네일을 표출하는 모든 소스를 다 원본파일불러오는걸로 수정하셔야해요.

 

그리고 썸네일로 변환하는걸 다 지우신 후에 엑박이 뜨는 이유는 썸네일을 보여주게 하는 소스인데 썸네일이 없어서 그래요.

 

썸네일 생성을 지우지 마시고 원본파일을 보여주려고 하는 페이지의 소스를 썸네일에서 원본소스명이 되는 것으로 바꿔주시면 되요.

아래가 원본파일 보여주는 페이지 소스인데요,
원본파일이 출력 되려면 어떻게 해야할까요?
//원본 이라고 주석처리된 부분의 $list[$i][file][0][file] 이 명령어가 원본파일을 가져 오지 못하는 것 같아요...



<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가 
include_once("./gnu/lib/thumb.lib.php");

//$cols  = 1; //  이미지 가로갯수 //  이미지 세로 갯수는 메인에서 지정(총 이미지 수)
//$image_h  = 1; // 이미지 상하 간격

$col_width = (int)(99 / $cols);

$data_path = "./gnu/data/file/$board_id";
$thumb_path = $data_path;
?>


<div class="moa_main_cont_right02">
				      <ul>
<?
for ($i=0; $i<count($list); $i++) { 

$image = $list[$i][file][0][file]; //원본
$img=$data_path. "/".$image;  //썸네일이 없을경우 원본출력
$thumb = $thumb_path. "/". $list[$i][wr_10];



  if ( file_exists($thumb) )
	$img = $thumb;
  
    //$style = "font-family:돋움; font-size:9pt; color:#636363;";
    //if ($list[$i][icon_new])
    //$style = "style='font-family:돋움; font-size:9pt; color:#006F00;' ";
	//$subject = $list[$i][subject]; //제목 글자수 자르기

	//$bg = "";  //새글? 
    //if ($list[$i][icon_new])
      //  $bg="la_top_2.gif";
     //else
       // $bg="la_top_1.gif";
	    //echo $list[$i][icon_reply] . " ";
        echo "<li><a href='{$list[$i]['wr_link1']}'><img src='$img' border='0' width='236px' height='154px'></a></li>";
		//echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>";
		//echo "		<tr><td valign='top' align='center' width=80><a href='{$list[$i]['href']}'><img src='$img' width='75' height='60' border='0'></a></td>";
		//echo "		<td height='21' valign=top style='padding-left:5px;'><table width='100%' cellpadding='0' cellspacing='0' border='0'><tr><td><a href='{$list[$i]['href']}' style='color:#666666;'><b>{$subject}</b></a></td></tr><tr><td><a href='{$list[$i]['href']}' style='color:#666666;'>".cut_str(strip_tags($list[$i][wr_content]),50)."</a></td></tr></table></td></tr></table>";

} 
?>
</ul>
				  </div>
<?
$cnt = ($i%$cols); 
for ($k=$cnt; $k<$cols && $cnt; $k++) { 
    echo "<td width=$col_width%>&nbsp;</td>"; 
} 

if (count($list) == 0) { echo "<td height=80 align=center>게시물이 없습니다.</td>"; } 

답변을 작성하시기 전에 로그인 해주세요.
전체 27
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT